Skip to content

fix: do not load SPDX tag-value .spdx files as JSON #2363 - #2365

Open
Jean-Regis-M wants to merge 1 commit into
aboutcode-org:mainfrom
Jean-Regis-M:fix-spdx-tag-value-input
Open

Jean-Regis-M wants to merge 1 commit into
aboutcode-org:mainfrom
Jean-Regis-M:fix-spdx-tag-value-input

Conversation

@Jean-Regis-M

@Jean-Regis-M Jean-Regis-M commented Nov 22, 2026 •

Copy link
Copy Markdown

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 .spdx extension is treated as SPDX only when it contains an SPDX JSON document, so JSON documents saved as .spdx still work. .spdx.json and .spdx.yml are unchanged. I didn't fall back to YAML for .spdx on purpose: a tag-value document can parse as YAML (SPDXID: SPDXRef-DOCUMENT is a valid YAML mapping line).
  • get_manifest_resources(): a tag-value .spdx file 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 existing try, so malformed input raises the SPDX document "..." is not valid: ... error instead of a raw JSONDecodeError.

spdx.is_spdx_document() (scanpipe/pipes/spdx.py) now also parses a .spdx file as JSON, and resolve.py reuses 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_type returns None for a tag-value .spdx and "spdx" for SPDX JSON saved as .spdx; invalid JSON raises "is not valid"; tests for is_spdx_tag_value_file.
  • test_pipelines: load_sbom with toml.spdx.json plus a tag-value .spdx exits 0, loads the toml package, and records the warning on tag-value.spdx.
  • New fixture: scanpipe/tests/data/spdx/tag-value.spdx, the minimal document from the issue.

Results:

  • test_resolve and the two load_sbom SPDX tests: 28 OK. With resolve.py from main, all 4 new tests fail and the rest pass.
  • ruff check and ruff format --check: clean.
  • test_resolve, test_spdx, test_cyclonedx, test_pipelines, test_input, test_api: same results as main (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 on main there (SQLite, missing ctags/gettext) fail on both. CI on PostgreSQL is the authoritative run.

@tdruez tdruez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#2361 is now merged and conflicts with this PR in get_spdx_document_from_file. Could you rebase on main? While at it, please reuse spdx.is_spdx_document instead of adding is_spdx_json_document, which duplicates it.

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
Jean-Regis-M force-pushed the fix-spdx-tag-value-input branch from 611557c to 17ee844 Compare November 23, 2026 13:33
@Jean-Regis-M

Copy link
Copy Markdown
Author

Thanks @tdruez. Rebased on main (after #2361) and removed is_spdx_json_document: spdx.is_spdx_document() now also reads a .spdx file as JSON, and resolve.py uses it in get_default_package_type() and is_spdx_tag_value_file(). A tag-value document fails the JSON parse, so it is still reported as unsupported. get_spdx_document_from_file() keeps the case-insensitive suffix check from #2361, with the parsing moved inside the try. I added two cases to test_spdx_is_spdx_document (SPDX JSON saved as .spdx → True, tag-value .spdx → False). test_spdx + test_resolve (52) and the SBOM pipeline tests (6) pass; ruff is clean.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

load_sbom fails with JSONDecodeError on SPDX tag-value (.spdx) files

2 participants