debug/elf: don't crash on empty symbol section

No test case because the problem can only happen for invalid data. Let
the fuzzer find cases like this.

Fixes #62649

Change-Id: Ia40b4d415e3bbffaffd143ee280949ba41346579
Reviewed-on: https://go-review.googlesource.com/c/go/+/528655
Auto-Submit: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Commit-Queue: Ian Lance Taylor <iant@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
This commit is contained in:
Ian Lance Taylor 2023-09-14 13:36:38 -07:00 committed by Gopher Robot
parent 5b37d720e3
commit 517c66d4ee

View file

@ -628,6 +628,9 @@ func (f *File) getSymbols32(typ SectionType) ([]Symbol, []byte, error) {
if err != nil {
return nil, nil, fmt.Errorf("cannot load symbol section: %w", err)
}
if len(data) == 0 {
return nil, nil, errors.New("symbol section is empty")
}
if len(data)%Sym32Size != 0 {
return nil, nil, errors.New("length of symbol section is not a multiple of SymSize")
}