From 1764e1c3f6bd66781f8350d957a1f95e4d9ad3de Mon Sep 17 00:00:00 2001 From: Avi Deitcher Date: Mon, 5 Jun 2023 22:04:14 +0300 Subject: [PATCH] fix: handle invalid symlinks (#1861) Signed-off-by: Avi Deitcher --- syft/internal/fileresolver/directory_indexer.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/syft/internal/fileresolver/directory_indexer.go b/syft/internal/fileresolver/directory_indexer.go index b4383d75d..6bdbae0c7 100644 --- a/syft/internal/fileresolver/directory_indexer.go +++ b/syft/internal/fileresolver/directory_indexer.go @@ -370,6 +370,13 @@ func (r directoryIndexer) addSymlinkToIndex(p string, info os.FileInfo) (string, metadata.LinkDestination = linkTarget r.index.Add(*ref, metadata) + // if the target path does not exist, then do not report it as a new root, or try to send + // syft parsing there. + if _, err := os.Stat(targetAbsPath); err != nil && errors.Is(err, os.ErrNotExist) { + log.Debugf("link %s points to unresolved path %s, ignoring target as new root", p, targetAbsPath) + targetAbsPath = "" + } + return targetAbsPath, nil }