fix: ask catalog for package, rather than type asserting #1857
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.
TODO
Explanation
Basically, when we're cataloging we remove some packages by ownership overlap, (e.g. if you're on redhat and do
yum install python3-urllib
, grype will drop the PyPI packageurllib
in favor of the RPMpython3-urllib
, because we have better match information for the distro package than for PyPI, e.g. because RedHad backported a fix to an old version of the python code or something).We do this:
Which seems fine, however, some relationships have a From of type
*pkg.Package
, not typepkg.Package
(pointer vs struct). This causes the type assertion in grype to always fail, resulting FPs.The underlying reason is that the syft scanner does this:
when building the relationship. And catalog.Package(id) returns a
*Package
.However, when we're decoding an SBOM, the relationship builder looks over
catalog.Sorted()
, which is a[]Package
.We can compensate for this in grype by trying to type assert to both
pkg.Package
and*pkg.Package
. I think that's the easier way, and I feel like the "right" way (making Syft either always put a pointer in the To/From field of a relationship or never do so) might end up breaking the type signature of something exported, which we wanted to avoid in 1.0. Grype PR soon, but definitely open to feedback on the approach.