diff options
| author | Ian Lance Taylor <iant@golang.org> | 2023-04-24 17:27:33 -0700 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-05-01 02:25:16 +0000 |
| commit | 069f9fb20548e904cb94f165f4cbf716a0fc108e (patch) | |
| tree | 7c48e73ad22e83fabf10954145f0dd69d4e9b584 /src/debug/pe/section.go | |
| parent | 2380d17aea2f1b5d6f379b76152b20f7a820ed9f (diff) | |
| download | go-069f9fb20548e904cb94f165f4cbf716a0fc108e.tar.xz | |
debug/pe: return error on reading from section with uninitialized data
A section with uninitialized data contains no bytes and occupies
no space in the file. This change makes it return an error on reading
from this section so that it will force the caller to check for
a section with uninitialized data.
This is the debug/pe version of CL 429601.
This will break programs that expect a byte slice with the length
described by the SizeOfRawData field. There are two reasons to
introduce this breaking change: 1) uninitialized data is uninitialized
and there is no reason to allocate memory for it; 2) it could result
in an OOM if the file is corrupted and has a large invalid SizeOfRawData.
No test case because the problem can only happen for invalid data. Let
the fuzzer find cases like this.
For #47653
Fixes #59817
Change-Id: I1ae94e9508f803b37926275d9a571f724a09af9f
Reviewed-on: https://go-review.googlesource.com/c/go/+/488475
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: kortschak <dan@kortschak.io>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/debug/pe/section.go')
| -rw-r--r-- | src/debug/pe/section.go | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/debug/pe/section.go b/src/debug/pe/section.go index fabb47af2e..70d0c220ce 100644 --- a/src/debug/pe/section.go +++ b/src/debug/pe/section.go @@ -97,11 +97,17 @@ type Section struct { } // Data reads and returns the contents of the PE section s. +// +// If s.Offset is 0, the section has no contents, +// and Data will always return a non-nil error. func (s *Section) Data() ([]byte, error) { return saferio.ReadDataAt(s.sr, uint64(s.Size), 0) } // Open returns a new ReadSeeker reading the PE section s. +// +// If s.Offset is 0, the section has no contents, and all calls +// to the returned reader will return a non-nil error. func (s *Section) Open() io.ReadSeeker { return io.NewSectionReader(s.sr, 0, 1<<63-1) } |
