From 25ae7bf55f36fc8bf786b3eb79639b8af9539fee Mon Sep 17 00:00:00 2001 From: Alex Goodman Date: Tue, 13 Feb 2024 10:12:31 -0500 Subject: [PATCH] fix getting union reader for sif images (#2631) Signed-off-by: Alex Goodman --- syft/file/cataloger/executable/cataloger.go | 10 +++++++++- syft/internal/unionreader/union_reader.go | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/syft/file/cataloger/executable/cataloger.go b/syft/file/cataloger/executable/cataloger.go index 301b31ba4..e75eb813f 100644 --- a/syft/file/cataloger/executable/cataloger.go +++ b/syft/file/cataloger/executable/cataloger.go @@ -66,7 +66,15 @@ func (i *Cataloger) Catalog(resolver file.Resolver) (map[file.Coordinates]file.E log.WithFields("error", err).Warnf("unable to get file contents for %q", loc.RealPath) continue } - exec, err := processExecutable(loc, reader.(unionreader.UnionReader)) + + uReader, err := unionreader.GetUnionReader(reader) + if err != nil { + // TODO: known-unknowns + log.WithFields("error", err).Warnf("unable to get union reader for %q", loc.RealPath) + continue + } + + exec, err := processExecutable(loc, uReader) if err != nil { log.WithFields("error", err).Warnf("unable to process executable %q", loc.RealPath) } diff --git a/syft/internal/unionreader/union_reader.go b/syft/internal/unionreader/union_reader.go index 2e7546304..86a493ad0 100644 --- a/syft/internal/unionreader/union_reader.go +++ b/syft/internal/unionreader/union_reader.go @@ -9,7 +9,7 @@ import ( "github.com/anchore/syft/internal/log" ) -// unionReader is a single interface with all reading functions needed by multi-arch binary catalogers +// UnionReader is a single interface with all reading functions needed by multi-arch binary catalogers // cataloger. type UnionReader interface { io.Reader @@ -18,7 +18,7 @@ type UnionReader interface { io.Closer } -// getReaders extracts one or more io.ReaderAt objects representing binaries that can be processed (multiple binaries in the case for multi-architecture binaries). +// GetReaders extracts one or more io.ReaderAt objects representing binaries that can be processed (multiple binaries in the case for multi-architecture binaries). func GetReaders(f UnionReader) ([]io.ReaderAt, error) { if macho.IsUniversalMachoBinary(f) { machoReaders, err := macho.ExtractReaders(f)