From e7cfcda67d430a6e3cf4e8dfef27416870a2b007 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 22 Feb 2023 13:00:14 -0800 Subject: [PATCH] debug/macho: don't crash if dynamic symtab with no symtab No test case because the problem can only happen for invalid data. Let the fuzzer find cases like this. For #47653 Fixes #58642 Change-Id: I19fee0dc9bd6239b520c15182b8f1e57bb0049bb Reviewed-on: https://go-review.googlesource.com/c/go/+/470397 Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor Auto-Submit: Ian Lance Taylor Run-TryBot: Ian Lance Taylor TryBot-Result: Gopher Robot Reviewed-by: Bryan Mills --- src/debug/macho/file.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/debug/macho/file.go b/src/debug/macho/file.go index 9806c270bfadc..3e339c32c6a2f 100644 --- a/src/debug/macho/file.go +++ b/src/debug/macho/file.go @@ -350,7 +350,9 @@ func NewFile(r io.ReaderAt) (*File, error) { if err := binary.Read(b, bo, &hdr); err != nil { return nil, err } - if hdr.Iundefsym > uint32(len(f.Symtab.Syms)) { + if f.Symtab == nil { + return nil, &FormatError{offset, "dynamic symbol table seen before any ordinary symbol table", nil} + } else if hdr.Iundefsym > uint32(len(f.Symtab.Syms)) { return nil, &FormatError{offset, fmt.Sprintf( "undefined symbols index in dynamic symbol table command is greater than symbol table length (%d > %d)", hdr.Iundefsym, len(f.Symtab.Syms)), nil}