Repository navigation
fix: do not load SPDX tag-value .spdx files as JSON #2363 - #2365
Open
Jean-Regis-M wants to merge 1 commit into
Open
Jean-Regis-M wants to merge 1 commit into
Jean-Regis-M wants to merge 1 commit into
Conversation
get_default_package_type() returned "spdx" for any ".spdx" file, and get_spdx_document_from_file() then parsed it with json.loads(). ".spdx" is the usual extension of the SPDX tag-value format, so a tag-value file made load_sbom fail with a raw JSONDecodeError, even when the input also contained valid SBOMs. - Only consider a ".spdx" file as SPDX when it contains an SPDX JSON document. ".spdx.json" and ".spdx.yml" are unchanged. - Add a project warning for a tag-value ".spdx" file, so the other SBOMs are still loaded. - Parse the document inside the try block of get_spdx_document_from_file, so invalid JSON/YAML raises the "SPDX document ... is not valid" error. Signed-off-by: JEAN REGIS <190766850+Jean-Regis-M@users.noreply.github.com>
Jean-Regis-M
force-pushed
the
fix-spdx-tag-value-input
branch
from
November 23, 2026 13:33
611557c to
17ee844
Compare
Author
|
Thanks @tdruez. Rebased on |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2363
This implements option 1 from the issue: SPDX tag-value input is not supported yet, so it is reported clearly instead of crashing the pipeline.
Changes (
scanpipe/pipes/resolve.py)get_default_package_type(): a file with the bare.spdxextension is treated as SPDX only when it contains an SPDX JSON document, so JSON documents saved as.spdxstill work..spdx.jsonand.spdx.ymlare unchanged. I didn't fall back to YAML for.spdxon purpose: a tag-value document can parse as YAML (SPDXID: SPDXRef-DOCUMENTis a valid YAML mapping line).get_manifest_resources(): a tag-value.spdxfile gets a project warning ("SPDX tag-value documents are not supported, please provide the SPDX document in JSON or YAML format.") linked to the resource. The run continues, and other SBOMs in the input are still loaded.get_spdx_document_from_file(): JSON/YAML parsing moves inside the existingtry, so malformed input raises theSPDX document "..." is not valid: ...error instead of a rawJSONDecodeError.spdx.is_spdx_document()(scanpipe/pipes/spdx.py) now also parses a.spdxfile as JSON, andresolve.pyreuses it for the checks above. A tag-value document fails to parse as JSON, so it is still not an SPDX document there.Tests
test_resolve:get_default_package_typereturnsNonefor a tag-value.spdxand"spdx"for SPDX JSON saved as.spdx; invalid JSON raises "is not valid"; tests foris_spdx_tag_value_file.test_pipelines:load_sbomwithtoml.spdx.jsonplus a tag-value.spdxexits 0, loads the toml package, and records the warning ontag-value.spdx.scanpipe/tests/data/spdx/tag-value.spdx, the minimal document from the issue.Results:
test_resolveand the twoload_sbomSPDX tests: 28 OK. Withresolve.pyfrommain, all 4 new tests fail and the rest pass.ruff checkandruff format --check: clean.test_resolve,test_spdx,test_cyclonedx,test_pipelines,test_input,test_api: same results asmain(236 vs 233 tests, the difference being the new tests). This ran on SQLite under WSL because Docker was unavailable, so 13 pipeline/API tests that also fail onmainthere (SQLite, missing ctags/gettext) fail on both. CI on PostgreSQL is the authoritative run.