From dbd0ce84d7c1da2e788c516c72fef44d5b760337 Mon Sep 17 00:00:00 2001 From: Dan Kortschak Date: Sat, 27 Aug 2022 12:55:43 +0930 Subject: [PATCH] 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 --- src/debug/elf/file.go | 6 ++++++ 1 file changed, 6 insertions(+) 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 -- 2.50.0