Skip to content

Commit

Permalink
debug/macho: don't crash if dynamic symtab with no symtab
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
ianlancetaylor authored and gopherbot committed Feb 22, 2023
1 parent 06b6759 commit e7cfcda
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/debug/macho/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit e7cfcda

Please sign in to comment.