Repository navigation
feat: improved sbom filename extension handling - #4919
Closed
Saksham-Sirohi wants to merge 3 commits into
Closed
Saksham-Sirohi wants to merge 3 commits into
Saksham-Sirohi wants to merge 3 commits into
Conversation
Saksham-Sirohi
force-pushed
the
improved-sbom-filename-extension-handling
branch
from
March 13, 2025 09:43
4389a69 to
780892a
Compare
Contributor
Author
|
hi @terriko required changes for URL sanitation has been made please take a look |
Collaborator
|
Ugh, looking at this again, I realize that we're going to have issues because splitting on |
4 tasks done
vineoy
added a commit
to vineoy/cve-bin-tool
that referenced
this pull request
Oct 23, 2026
lib4sbom's parser selects the file format from the filename extension and rejects files with an unknown (or absent) extension without even looking at their content, so an SBOM file without an extension could crash cve-bin-tool with a confusing SBOMParserException traceback or fail auto-detection silently. - SBOMParse now falls back to identifying the file format from the file contents (lib4sbom parse_string) when the extension is not recognised, with clear warnings stating the detected format - non-SBOM content and files without components now produce clear error messages instead of a raw parser exception or KeyErrors - sbom_detection() identifies CycloneDX, SWID and SPDX (json/yaml/tag) data from file contents, and falls back on 'sbom.spdx.*' style names; extension handling is done with pathlib instead of substrings - add_extension_if_not() rewritten with pathlib (per code-review guidance on PR ossf#4919), keeping multi-dot names and its extension behaviour intact while supporting SBOM extensions (spdx, yaml) - SPDX SBOM generation now appends the proper extension for the used format (tag -> .spdx, json -> .json, yaml -> .yaml) - documented that SBOM files without matching extensions are identified from contents Fixes ossf#4836 Signed-off-by: vinayak <singhvinayak288@gmail.com>
vineoy
added a commit
to vineoy/cve-bin-tool
that referenced
this pull request
Oct 27, 2026
lib4sbom's parser selects the file format from the filename extension and rejects files with an unknown (or absent) extension without even looking at their content, so an SBOM file without a recognised extension could crash cve-bin-tool with a raw SBOMParserException traceback (issue ossf#4836) or fail auto-detection silently. - SBOMParse now catches SBOMParserException and reports a clear error message instead of a traceback - an SBOM without any software components now produces a clear error message instead of a KeyError traceback - sbom_detection() identifies CycloneDX, SWID and SPDX (json/yaml/tag) data from file contents, falling back on 'sbom.spdx.*' style names; extension handling is done with pathlib instead of substrings - add_extension_if_not() rewritten with pathlib (per code-review guidance on PR ossf#4919), keeping multi-dot names and its extension behaviour intact while supporting SBOM extensions (spdx, yaml) - SPDX SBOM generation now appends the proper extension for the used format (tag -> .spdx, json -> .json, yaml -> .yaml) - documented that SBOM files which do not follow the filename conventions produce an error message instead of a traceback Content-based parsing of SBOM files whose filename extension is not recognised is being implemented upstream in lib4sbom (anthonyharrison/lib4sbom#102); once that is released, cve-bin-tool will be able to read SBOM files regardless of their filename extension. Signed-off-by: vinayak <singhvinayak288@gmail.com>
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.
Summary
This PR fixes SBOM parsing test failures caused by invalid CycloneDX file extensions. It enforces strict extension validation for CycloneDX files and improves error handling while ensuring backward compatibility.
Changes Introduced
.jsonor.xmlextensions. Invalid extensions trigger explicit error logging.test/sbomdirectory.parse.py.Checklist
Steps to Test
pytest test/test_sbom.py -vVerified
Related Issues
Fixes #4836