Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic on empty sbom #917

Merged
merged 3 commits into from Mar 24, 2022
Merged

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.

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants