From 0442e56e63129d1723accd84778f978abe52c87c Mon Sep 17 00:00:00 2001 From: Keith Zantow Date: Wed, 28 Sep 2022 09:56:23 -0400 Subject: [PATCH 1/2] fix: do not fail if unable to parse .rpm file Signed-off-by: Keith Zantow --- syft/pkg/cataloger/rpm/file_cataloger.go | 5 ++++- syft/pkg/cataloger/rpm/file_cataloger_test.go | 3 +++ syft/pkg/cataloger/rpm/test-fixtures/bad/bad.rpm | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 syft/pkg/cataloger/rpm/test-fixtures/bad/bad.rpm diff --git a/syft/pkg/cataloger/rpm/file_cataloger.go b/syft/pkg/cataloger/rpm/file_cataloger.go index 6ae85de0d0a0..f7264e52dd04 100644 --- a/syft/pkg/cataloger/rpm/file_cataloger.go +++ b/syft/pkg/cataloger/rpm/file_cataloger.go @@ -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" @@ -28,6 +29,7 @@ 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 { @@ -43,7 +45,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() diff --git a/syft/pkg/cataloger/rpm/file_cataloger_test.go b/syft/pkg/cataloger/rpm/file_cataloger_test.go index da4752d5b921..a576d2956c5b 100644 --- a/syft/pkg/cataloger/rpm/file_cataloger_test.go +++ b/syft/pkg/cataloger/rpm/file_cataloger_test.go @@ -79,6 +79,9 @@ func TestParseRpmFiles(t *testing.T) { }, }, }, + { + fixture: "test-fixtures/bad", + }, } for _, test := range tests { diff --git a/syft/pkg/cataloger/rpm/test-fixtures/bad/bad.rpm b/syft/pkg/cataloger/rpm/test-fixtures/bad/bad.rpm new file mode 100644 index 000000000000..b71ddee25b75 --- /dev/null +++ b/syft/pkg/cataloger/rpm/test-fixtures/bad/bad.rpm @@ -0,0 +1 @@ +this is not a real RPM file \ No newline at end of file From 5954c24bf2fa1e0d526af20a8a5cdb8716d91916 Mon Sep 17 00:00:00 2001 From: Keith Zantow Date: Wed, 28 Sep 2022 10:25:50 -0400 Subject: [PATCH 2/2] lint Signed-off-by: Keith Zantow --- syft/pkg/cataloger/rpm/file_cataloger.go | 1 + 1 file changed, 1 insertion(+) diff --git a/syft/pkg/cataloger/rpm/file_cataloger.go b/syft/pkg/cataloger/rpm/file_cataloger.go index f7264e52dd04..693349ca65e6 100644 --- a/syft/pkg/cataloger/rpm/file_cataloger.go +++ b/syft/pkg/cataloger/rpm/file_cataloger.go @@ -29,6 +29,7 @@ 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")