From: Ian Lance Taylor Date: Sat, 25 Jun 2022 22:28:15 +0000 (-0700) Subject: debug/plan9obj: use saferio to read section data X-Git-Tag: go1.20rc1~1495 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=1c4a80377580a05b9c3f1cccb66baefc01383352;p=gostls13.git 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 --- 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.