From 5ceef489494ba79e4074670a6fa52034d41ee6f9 Mon Sep 17 00:00:00 2001 From: Chris Selzo Date: Thu, 24 Aug 2023 07:45:22 -0700 Subject: [PATCH] fix: do not double-prefix symlink paths that already contain volume names (#2051) Signed-off-by: Joseph Palermo Signed-off-by: Chris Selzo Co-authored-by: Joseph Palermo --- syft/internal/fileresolver/directory_indexer.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/syft/internal/fileresolver/directory_indexer.go b/syft/internal/fileresolver/directory_indexer.go index c9b5567a93d..b6432f0007e 100644 --- a/syft/internal/fileresolver/directory_indexer.go +++ b/syft/internal/fileresolver/directory_indexer.go @@ -349,9 +349,13 @@ func (r directoryIndexer) addSymlinkToIndex(p string, info os.FileInfo) (string, } if filepath.IsAbs(linkTarget) { + linkTarget = filepath.Clean(linkTarget) // if the link is absolute (e.g, /bin/ls -> /bin/busybox) we need to - // resolve relative to the root of the base directory - linkTarget = filepath.Join(r.base, filepath.Clean(linkTarget)) + // resolve relative to the root of the base directory, if it is not already + // prefixed with a volume name + if filepath.VolumeName(linkTarget) == "" { + linkTarget = filepath.Join(r.base, filepath.Clean(linkTarget)) + } } else { // if the link is not absolute (e.g, /dev/stderr -> fd/2 ) we need to // resolve it relative to the directory in question (e.g. resolve to