From ac94bf530c7b1e6ee5df1ed0f9f6454fca8bc918 Mon Sep 17 00:00:00 2001 From: Keith Zantow Date: Thu, 12 Jan 2023 17:42:13 -0500 Subject: [PATCH] fix: update graalvm cataloger to fix panic (#1454) Fixes https://github.com/anchore/syft/issues/1453 --- .../cataloger/java/graalvm_native_image_cataloger.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/syft/pkg/cataloger/java/graalvm_native_image_cataloger.go b/syft/pkg/cataloger/java/graalvm_native_image_cataloger.go index 7a73966c1c3..4a4955d4201 100644 --- a/syft/pkg/cataloger/java/graalvm_native_image_cataloger.go +++ b/syft/pkg/cataloger/java/graalvm_native_image_cataloger.go @@ -231,8 +231,15 @@ func newPE(filename string, r io.ReaderAt) (nativeImage, error) { if err != nil { return fileError(filename, err) } - optionalHeader := bi.OptionalHeader.(*pe.OptionalHeader64) - exportSymbolsDataDirectory := optionalHeader.DataDirectory[0] + var exportSymbolsDataDirectory pe.DataDirectory + switch h := bi.OptionalHeader.(type) { + case *pe.OptionalHeader32: + exportSymbolsDataDirectory = h.DataDirectory[0] + case *pe.OptionalHeader64: + exportSymbolsDataDirectory = h.DataDirectory[0] + default: + return nil, fmt.Errorf("unable to get exportSymbolsDataDirectory from binary: %s", filename) + } // If we have no exported symbols it is not a Native Image if exportSymbolsDataDirectory.Size == 0 { return fileError(filename, errors.New(nativeImageMissingExportedDataDirectoryError))