From 065ac13ab726f00e2f32a243c23a598d820ae25b Mon Sep 17 00:00:00 2001 From: Kudryavcev Nikolay <35200428+Rupikz@users.noreply.github.com> Date: Wed, 15 Oct 2025 19:05:05 +0300 Subject: [PATCH] Extract zip archive with multiple entries (#4283) * extract zip archive with multiple entries Signed-off-by: Kudryavcev Nikolay * set OverwriteExisting by type assertion switch case Signed-off-by: Kudryavcev Nikolay --------- Signed-off-by: Kudryavcev Nikolay --- syft/source/filesource/file_source.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/syft/source/filesource/file_source.go b/syft/source/filesource/file_source.go index aa4b4df4b..f74b0c089 100644 --- a/syft/source/filesource/file_source.go +++ b/syft/source/filesource/file_source.go @@ -231,11 +231,14 @@ func fileAnalysisPath(path string, skipExtractArchive bool) (string, func() erro // unarchived. envelopedUnarchiver, err := archiver.ByExtension(path) if unarchiver, ok := envelopedUnarchiver.(archiver.Unarchiver); err == nil && ok { - if tar, ok := unarchiver.(*archiver.Tar); ok { - // when tar files are extracted, if there are multiple entries at the same - // location, the last entry wins - // NOTE: this currently does not display any messages if an overwrite happens - tar.OverwriteExisting = true + // when tar/zip files are extracted, if there are multiple entries at the same + // location, the last entry wins + // NOTE: this currently does not display any messages if an overwrite happens + switch v := unarchiver.(type) { + case *archiver.Tar: + v.OverwriteExisting = true + case *archiver.Zip: + v.OverwriteExisting = true } analysisPath, cleanupFn, err = unarchiveToTmp(path, unarchiver)