From bfe0729406b9e387db2c7dd2412231b3d1656740 Mon Sep 17 00:00:00 2001 From: Justin Chadwell Date: Tue, 7 Feb 2023 13:09:06 +0000 Subject: [PATCH] exporter: canonicalize sbom file paths during search Signed-off-by: Justin Chadwell (cherry picked from commit e4c7c6dc417d5079803d77dfa5b42fa626227e2f) --- exporter/containerimage/attestations.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/exporter/containerimage/attestations.go b/exporter/containerimage/attestations.go index 782c18733035..af3962393187 100644 --- a/exporter/containerimage/attestations.go +++ b/exporter/containerimage/attestations.go @@ -172,6 +172,8 @@ func newFileLayerFinder(target cache.ImmutableRef, remote *solver.Remote) (fileL // // find is not concurrency-safe. func (c *fileLayerFinder) find(ctx context.Context, s session.Group, filename string) (cache.ImmutableRef, *ocispecs.Descriptor, error) { + filename = filepath.Join("/", filename) + // return immediately if we've already found the layer containing filename if cache, ok := c.cache[filename]; ok { return cache.ref, &cache.desc, nil @@ -188,6 +190,8 @@ func (c *fileLayerFinder) find(ctx context.Context, s session.Group, filename st found := false for _, f := range files { + f = filepath.Join("/", f) + if strings.HasPrefix(f, ".wh.") { // skip whiteout files, we only care about file creations continue