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: Only remove packages by binary overlap #1444

Merged
merged 1 commit into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions grype/pkg/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ func excludePackage(p pkg.Package, parent pkg.Package) bool {
return false
}

// filter out only binary pkg, empty types, or equal types
if p.Type != pkg.BinaryPkg && p.Type != "" && p.Type != parent.Type {
// filter out only binary pkg
if p.Type != pkg.BinaryPkg {
return false
}

Expand Down
18 changes: 16 additions & 2 deletions grype/pkg/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,11 +676,25 @@ func Test_RemoveBinaryPackagesByOverlap(t *testing.T) {
[]string{"apk:[email protected] -> binary:[email protected]"}),
expectedPackages: []string{"apk:[email protected]", "apk:[email protected]"},
},
{
name: "does not exclude if OS package owns OS package",
sbom: catalogWithOverlaps(
[]string{"rpm:[email protected]", "rpm:[email protected]"},
[]string{"rpm:[email protected] -> rpm:[email protected]"}),
expectedPackages: []string{"rpm:[email protected]", "rpm:[email protected]"},
},
{
name: "does not exclude if owning package is non-OS",
sbom: catalogWithOverlaps(
[]string{"python:[email protected]", "python:[email protected]"},
[]string{"python:[email protected] -> python:[email protected]"}),
expectedPackages: []string{"python:[email protected]", "python:[email protected]"},
},
{
name: "excludes multiple package by overlap",
sbom: catalogWithOverlaps(
[]string{"apk:[email protected]", "apk:[email protected]", "binary:[email protected]", "apk:[email protected]", ":[email protected]"},
[]string{"apk:[email protected] -> binary:[email protected]", "apk:[email protected] -> :[email protected]"}),
[]string{"apk:[email protected]", "apk:[email protected]", "binary:[email protected]", "apk:[email protected]", "binary:[email protected]"},
[]string{"apk:[email protected] -> binary:[email protected]", "apk:[email protected] -> binary:[email protected]"}),
expectedPackages: []string{"apk:[email protected]", "apk:[email protected]", "apk:[email protected]"},
},
{
Expand Down