aboutsummaryrefslogtreecommitdiff
path: root/src/debug
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2022-06-25 15:28:15 -0700
committerGopher Robot <gobot@golang.org>2022-08-19 21:29:13 +0000
commit1c4a80377580a05b9c3f1cccb66baefc01383352 (patch)
treec82765f253236f28b92eccfe2e331f34e2ba2681 /src/debug
parent5f0170f9a529c7113ac12f1270e00e5bdc444803 (diff)
downloadgo-1c4a80377580a05b9c3f1cccb66baefc01383352.tar.xz
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 <iant@google.com> Reviewed-by: Dan Kortschak <dan@kortschak.io> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Diffstat (limited to 'src/debug')
-rw-r--r--src/debug/plan9obj/file.go8
1 files 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.