Do not fail if unable to parse .rpm file (#1232)

This commit is contained in:
Keith Zantow 2022-09-28 11:26:06 -04:00 committed by GitHub
parent 16c62a1378
commit 6a40dbf765
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 1 deletions

View File

@ -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,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 {
@ -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()

View File

@ -79,6 +79,9 @@ func TestParseRpmFiles(t *testing.T) {
},
},
},
{
fixture: "test-fixtures/bad",
},
}
for _, test := range tests {

View File

@ -0,0 +1 @@
this is not a real RPM file