Skip to content

Commit

Permalink
Do not fail if unable to parse .rpm file (#1232)
Browse files Browse the repository at this point in the history
  • Loading branch information
kzantow committed Sep 28, 2022
1 parent 16c62a1 commit 6a40dbf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion syft/pkg/cataloger/rpm/file_cataloger.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/sassoftware/go-rpmutils"

"github.com/anchore/syft/internal"
"github.com/anchore/syft/internal/log"
"github.com/anchore/syft/syft/artifact"
"github.com/anchore/syft/syft/file"
"github.com/anchore/syft/syft/pkg"
Expand All @@ -28,6 +29,8 @@ func (c *FileCataloger) Name() string {
}

// Catalog is given an object to resolve file references and content, this function returns any discovered Packages after analyzing rpm files
//
//nolint:funlen
func (c *FileCataloger) Catalog(resolver source.FileResolver) ([]pkg.Package, []artifact.Relationship, error) {
fileMatches, err := resolver.FilesByGlob("**/*.rpm")
if err != nil {
Expand All @@ -43,7 +46,8 @@ func (c *FileCataloger) Catalog(resolver source.FileResolver) ([]pkg.Package, []

rpm, err := rpmutils.ReadRpm(contentReader)
if err != nil {
return nil, nil, err
log.Debugf("RPM file found but unable to read: %s (%v)", location.RealPath, err)
continue
}

nevra, err := rpm.Header.GetNEVRA()
Expand Down
3 changes: 3 additions & 0 deletions syft/pkg/cataloger/rpm/file_cataloger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ func TestParseRpmFiles(t *testing.T) {
},
},
},
{
fixture: "test-fixtures/bad",
},
}

for _, test := range tests {
Expand Down
1 change: 1 addition & 0 deletions syft/pkg/cataloger/rpm/test-fixtures/bad/bad.rpm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is not a real RPM file

0 comments on commit 6a40dbf

Please sign in to comment.