Repository navigation
fix: unhandled AttributeError on JSON and YAML lists in is_spdx_document - #2361
Conversation
Jean-Regis-M
left a comment
There was a problem hiding this comment.
The isinstance(data, dict) guard fixes #2360 cleanly, and the tests cover the list and primitive cases well.
One concern about the case-insensitive extension part. It isn't reachable from the pipeline and doesn't match the loader:
- The only caller,
get_default_package_typeinscanpipe/pipes/resolve.py(~line 510), only reachesis_spdx_documentafter a case-sensitiveinput_location.endswith((".json", ".xml", ".yml", ".yaml")). Sotest.JSON/test.YMLnever get here during a run. - If that gate were relaxed later,
get_spdx_document_from_file(~line 454) still picks the parser with a case-sensitive.endswith((".yml", ".yaml")). Afoo.YMLSPDX doc would be detected as SPDX and then go throughjson.loads, ending in a confusing "SPDX document ... is not valid" error.
I'd either drop the .lower() change so this PR stays focused on the AttributeError, or apply the same case handling to those two spots in resolve.py (and cyclonedx.py:145/315 if consistency matters) with a test that goes through get_default_package_type.
| """Return True if the file at `input_location` is a SPDX Document.""" | ||
| input_location = str(input_location) | ||
| data = {} | ||
| location_lower = str(input_location).lower() |
There was a problem hiding this comment.
Since #2360 explicitly asks for case-insensitive extensions, keeping this and making the two callers agree seems like the better of the two options I mentioned. Something like this in scanpipe/pipes/resolve.py:
# get_spdx_document_from_file (~L454)
if input_path.suffix.lower() in (".yml", ".yaml"):
# get_default_package_type (~L510)
if input_location.lower().endswith((".json", ".xml", ".yml", ".yaml")):A test that calls resolve.get_default_package_type() with an uppercase .JSON SPDX file would then cover the real entry point and not only the helper.
There was a problem hiding this comment.
Hi @Jean-Regis-M, thanks for the review and suggestions,
I have updated scanpipe/pipes/resolve.py so that both get_default_package_type() and get_spdx_document_from_file() handle extensions case-insensitively, agreeing with is_spdx_document().
I also added tests in scanpipe/tests/pipes/test_resolve.py covering uppercase .JSON and .YML SPDX files for both detection and parsing, and rebased the branch on latest main to resolve merge conflicts.
761c059 to
f1102db
Compare
Issues
Changes
scanpipe/pipes/spdx.py, handle non-dict JSON and YAML content by checkingisinstance(data, dict)insidewith suppress(Exception):before checking for"SPDXID"..json,.yml,.yaml).scanpipe/tests/pipes/test_spdx.pyfor JSON/YAML lists, non-dict content, empty files, and case-insensitive extensions.Checklist