Skip to content

Commit e7cfcda

Browse files
ianlancetaylorgopherbot
authored andcommitted
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 <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Bryan Mills <[email protected]>
1 parent 06b6759 commit e7cfcda

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/debug/macho/file.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,9 @@ func NewFile(r io.ReaderAt) (*File, error) {
350350
if err := binary.Read(b, bo, &hdr); err != nil {
351351
return nil, err
352352
}
353-
if hdr.Iundefsym > uint32(len(f.Symtab.Syms)) {
353+
if f.Symtab == nil {
354+
return nil, &FormatError{offset, "dynamic symbol table seen before any ordinary symbol table", nil}
355+
} else if hdr.Iundefsym > uint32(len(f.Symtab.Syms)) {
354356
return nil, &FormatError{offset, fmt.Sprintf(
355357
"undefined symbols index in dynamic symbol table command is greater than symbol table length (%d > %d)",
356358
hdr.Iundefsym, len(f.Symtab.Syms)), nil}

0 commit comments

Comments
 (0)