From 1d3a335088ab7e7d1ae7885992be9fc3c5ddbc25 Mon Sep 17 00:00:00 2001 From: Christopher Phillips Date: Mon, 28 Nov 2022 10:16:53 -0500 Subject: [PATCH] fix: guard for locations < 1 Signed-off-by: Christopher Phillips --- syft/pkg/cataloger/alpm/parse_alpm_db.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/syft/pkg/cataloger/alpm/parse_alpm_db.go b/syft/pkg/cataloger/alpm/parse_alpm_db.go index 98e3e56887a..5bc776a4443 100644 --- a/syft/pkg/cataloger/alpm/parse_alpm_db.go +++ b/syft/pkg/cataloger/alpm/parse_alpm_db.go @@ -42,10 +42,12 @@ func parseAlpmDB(resolver source.FileResolver, env *generic.Environment, reader if err != nil { return nil, nil, err } + pkgFiles, err := parseMtree(r) if err != nil { return nil, nil, err } + // The replace the files found the the pacman database with the files from the mtree These contain more metadata and // thus more useful. metadata.Files = pkgFiles @@ -106,6 +108,10 @@ func getFileReader(path string, resolver source.FileResolver) (io.Reader, error) if err != nil { return nil, err } + + if len(locs) == 0 { + return nil, fmt.Errorf("could not find file: %s", path) + } // TODO: Should we maybe check if we found the file dbContentReader, err := resolver.FileContentsByLocation(locs[0]) if err != nil {