From 1c4a80377580a05b9c3f1cccb66baefc01383352 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Sat, 25 Jun 2022 15:28:15 -0700 Subject: [PATCH] debug/plan9obj: use saferio to read section data Avoid allocating large amounts of memory for corrupt input. No test case because the problem can only happen for invalid data. Let the fuzzer find cases like this. Fixes #52521 Change-Id: I6a046f2e28e1255cf773ce135c5bb2b967ef43e9 Reviewed-on: https://go-review.googlesource.com/c/go/+/414234 Auto-Submit: Ian Lance Taylor Reviewed-by: Dan Kortschak TryBot-Result: Gopher Robot Run-TryBot: Ian Lance Taylor Reviewed-by: Ian Lance Taylor Reviewed-by: Dmitri Shuralyov --- src/debug/plan9obj/file.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/debug/plan9obj/file.go b/src/debug/plan9obj/file.go index aa03429624..aa25809148 100644 --- a/src/debug/plan9obj/file.go +++ b/src/debug/plan9obj/file.go @@ -9,6 +9,7 @@ import ( "encoding/binary" "errors" "fmt" + "internal/saferio" "io" "os" ) @@ -55,12 +56,7 @@ type Section struct { // Data reads and returns the contents of the Plan 9 a.out section. func (s *Section) Data() ([]byte, error) { - dat := make([]byte, s.sr.Size()) - n, err := s.sr.ReadAt(dat, 0) - if n == len(dat) { - err = nil - } - return dat[0:n], err + return saferio.ReadDataAt(s.sr, uint64(s.Size), 0) } // Open returns a new ReadSeeker reading the Plan 9 a.out section. -- 2.50.0