Skip to content

Fix panic on empty sbom#917

Merged
luhring merged 3 commits intoanchore:mainfrom
luhring:fix-panic-on-empty-sbom
Mar 24, 2022
Merged

Fix panic on empty sbom#917
luhring merged 3 commits intoanchore:mainfrom
luhring:fix-panic-on-empty-sbom

Conversation

@luhring
Copy link
Contributor

@luhring luhring commented Mar 24, 2022

In this PR:

  1. I added a failing test that loops through all formats used by the syft package to ensure that no formats panic when trying to decode or validate an empty SBOM.
  2. I fixed the failing test by adding a nil check to the SPDX document processing logic.

Additionally, for convenience, I implemented fmt.Stringer on the format.ID type for use in string descriptions of format operations. This can be undone if needed!

This prevents the panic shown in anchore/grype#693, but a separate Grype PR will catch the "empty SBOM" case even earlier to provide a more direct error message to the user. So this PR isn't strictly necessary with regard to anchore/grype#693, but it still fixes a panic case for the Syft library.

luhring added 3 commits March 24, 2022 07:42
Signed-off-by: Dan Luhring <dan+github@luhrings.com>
Signed-off-by: Dan Luhring <dan+github@luhrings.com>
Signed-off-by: Dan Luhring <dan+github@luhrings.com>
@luhring luhring merged commit a7db43f into anchore:main Mar 24, 2022
@luhring luhring deleted the fix-panic-on-empty-sbom branch March 24, 2022 14:11
GijsCalis pushed a commit to GijsCalis/syft that referenced this pull request Feb 19, 2024
* Implement fmt.Stringer with format.ID Signed-off-by: Dan Luhring <dan+github@luhrings.com> * Add failing test for formats processing empty SBOMs Signed-off-by: Dan Luhring <dan+github@luhrings.com> * Account for nil SPDX document during Syft model conversion Signed-off-by: Dan Luhring <dan+github@luhrings.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants