]> Cypherpunks repositories - gostls13.git/commitdiff
debug/plan9obj: use saferio to read section data
authorIan Lance Taylor <iant@golang.org>
Sat, 25 Jun 2022 22:28:15 +0000 (15:28 -0700)
committerGopher Robot <gobot@golang.org>
Fri, 19 Aug 2022 21:29:13 +0000 (21:29 +0000)
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>
src/debug/plan9obj/file.go

index aa0342962422a8500d0248ae68521207385eea38..aa25809148cd40605b754d477269ab7b0b6d79d8 100644 (file)
@@ -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.