From 61362c04fa5dfc5368a7ca15c35a91192f240156 Mon Sep 17 00:00:00 2001 From: Christopher Angelo Phillips <32073428+spiffcs@users.noreply.github.com> Date: Wed, 15 Mar 2023 15:29:10 -0400 Subject: [PATCH] fix: move defer after error to protect panic case (#1670) Signed-off-by: Christopher Phillips --- syft/source/source.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syft/source/source.go b/syft/source/source.go index b0cb948e0..29cfa4610 100644 --- a/syft/source/source.go +++ b/syft/source/source.go @@ -385,11 +385,11 @@ func (s *Source) SetID() { case FileScheme: // attempt to use the digest of the contents of the file as the ID file, err := os.Open(s.Metadata.Path) - defer file.Close() if err != nil { d = digest.FromString(s.Metadata.Path).String() break } + defer file.Close() di, err := digest.FromReader(file) if err != nil { d = digest.FromString(s.Metadata.Path).String()