Recover from panics from the stdlib when cataloging malformed binaries (#663)

* recover from panics in stdlib binary parsing

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>

* add CLI test to cover regression case

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
Alex Goodman
2021-12-10 11:49:50 -05:00
committed by GitHub
parent da0b17b719
commit ab9fe53ff2
7 changed files with 79 additions and 24 deletions
@@ -40,12 +40,12 @@ func (c *Cataloger) Catalog(resolver source.FileResolver) ([]pkg.Package, []arti
for _, location := range fileMatches {
r, err := resolver.FileContentsByLocation(location)
if err != nil {
return pkgs, nil, fmt.Errorf("failed to resolve file contents by location: %w", err)
return pkgs, nil, fmt.Errorf("failed to resolve file contents by location=%q: %w", location.RealPath, err)
}
goPkgs, err := parseGoBin(location, r)
goPkgs, err := parseGoBin(location, r, openExe)
if err != nil {
log.Warnf("could not parse possible go binary: %+v", err)
log.Warnf("could not parse possible go binary at %q: %+v", location.RealPath, err)
}
internal.CloseAndLogError(r, location.RealPath)