From: Dan Kortschak Date: Sat, 27 Aug 2022 03:25:43 +0000 (+0930) Subject: debug/elf: validate offset and file size ranges X-Git-Tag: go1.20rc1~1360 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=dbd0ce84d7c1da2e788c516c72fef44d5b760337;p=gostls13.git debug/elf: validate offset and file size ranges Change-Id: Iebe31b91c6e81438120f50a8089a8efca3d5339d Reviewed-on: https://go-review.googlesource.com/c/go/+/426115 Run-TryBot: Dan Kortschak Run-TryBot: Ian Lance Taylor Reviewed-by: Ian Lance Taylor Reviewed-by: Heschi Kreinick Auto-Submit: Ian Lance Taylor TryBot-Result: Gopher Robot --- diff --git a/src/debug/elf/file.go b/src/debug/elf/file.go index 95c28c1433..f37d4b8e9a 100644 --- a/src/debug/elf/file.go +++ b/src/debug/elf/file.go @@ -377,6 +377,12 @@ func NewFile(r io.ReaderAt) (*File, error) { Align: ph.Align, } } + if int64(p.Off) < 0 { + return nil, &FormatError{off, "invalid program header offset", p.Off} + } + if int64(p.Filesz) < 0 { + return nil, &FormatError{off, "invalid program header file size", p.Filesz} + } p.sr = io.NewSectionReader(r, int64(p.Off), int64(p.Filesz)) p.ReaderAt = p.sr f.Progs[i] = p