diff options
Diffstat (limited to 'src/debug/elf/file.go')
| -rw-r--r-- | src/debug/elf/file.go | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/debug/elf/file.go b/src/debug/elf/file.go index faba6fa4e9..e243b8a5f5 100644 --- a/src/debug/elf/file.go +++ b/src/debug/elf/file.go @@ -467,7 +467,14 @@ func NewFile(r io.ReaderAt) (*File, error) { } // Read program headers - f.Progs = make([]*Prog, phnum) + c := saferio.SliceCap[*Prog](uint64(phnum)) + if c < 0 { + return nil, &FormatError{0, "too many segments", phnum} + } + if phnum > 0 && ((1<<64)-1)/uint64(phnum) < uint64(phentsize) { + return nil, &FormatError{0, "segment header overflow", phnum} + } + f.Progs = make([]*Prog, 0, c) phdata, err := saferio.ReadDataAt(sr, uint64(phnum)*uint64(phentsize), phoff) if err != nil { return nil, err @@ -509,7 +516,7 @@ func NewFile(r io.ReaderAt) (*File, error) { } p.sr = io.NewSectionReader(r, int64(p.Off), int64(p.Filesz)) p.ReaderAt = p.sr - f.Progs[i] = p + f.Progs = append(f.Progs, p) } if shnum > 0 && shentsize < wantShentsize { @@ -517,7 +524,7 @@ func NewFile(r io.ReaderAt) (*File, error) { } // Read section headers - c := saferio.SliceCap[Section](uint64(shnum)) + c = saferio.SliceCap[Section](uint64(shnum)) if c < 0 { return nil, &FormatError{0, "too many sections", shnum} } |
