aboutsummaryrefslogtreecommitdiff
path: root/src/debug/pe/string.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2022-05-28 17:46:38 -0700
committerGopher Robot <gobot@golang.org>2022-08-11 20:05:25 +0000
commit141f15303d528620a8855fd73d19fe51dd2479f0 (patch)
tree717530760ec9fc1839404d9b5d43839c62ef9cd6 /src/debug/pe/string.go
parent527565b1f1997f05d9902d30118a0d6003674b66 (diff)
downloadgo-141f15303d528620a8855fd73d19fe51dd2479f0.tar.xz
internal/saferio: new package to avoid OOM
Broken out of debug/pe. Update debug/pe to use it. For #47653 Change-Id: Ib3037ee04073e005c4b435d0128b8437a075b00a Reviewed-on: https://go-review.googlesource.com/c/go/+/408678 Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Dan Kortschak <dan@kortschak.io> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/debug/pe/string.go')
-rw-r--r--src/debug/pe/string.go24
1 files changed, 2 insertions, 22 deletions
diff --git a/src/debug/pe/string.go b/src/debug/pe/string.go
index 6d9023d8d6..a156bbef05 100644
--- a/src/debug/pe/string.go
+++ b/src/debug/pe/string.go
@@ -8,6 +8,7 @@ import (
"bytes"
"encoding/binary"
"fmt"
+ "internal/saferio"
"io"
)
@@ -45,28 +46,7 @@ func readStringTable(fh *FileHeader, r io.ReadSeeker) (StringTable, error) {
}
l -= 4
- // If the string table is large, the file may be corrupt.
- // Read in chunks to avoid crashing due to out of memory.
- const chunk = 10 << 20 // 10M
- var buf []byte
- if l < chunk {
- buf = make([]byte, l)
- _, err = io.ReadFull(r, buf)
- } else {
- for l > 0 {
- n := l
- if n > chunk {
- n = chunk
- }
- buf1 := make([]byte, n)
- _, err = io.ReadFull(r, buf1)
- if err != nil {
- break
- }
- buf = append(buf, buf1...)
- l -= n
- }
- }
+ buf, err := saferio.ReadData(r, uint64(l))
if err != nil {
return nil, fmt.Errorf("fail to read string table: %v", err)
}