Skip to content

Commit 0c6d8bb

Browse files
ianlancetaylorgopherbot
authored andcommitted
debug/pe: read string table in 10M chunks
No separate test because this makes no difference for valid PE files. Fixes #52350 Change-Id: I2aa011a4e8b34cb08052222e94c52627ebe99fbf Reviewed-on: https://go-review.googlesource.com/c/go/+/400378 Run-TryBot: Ian Lance Taylor <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Than McIntosh <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]>
1 parent df2421d commit 0c6d8bb

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/debug/pe/string.go

+23-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,29 @@ func readStringTable(fh *FileHeader, r io.ReadSeeker) (StringTable, error) {
4444
return nil, nil
4545
}
4646
l -= 4
47-
buf := make([]byte, l)
48-
_, err = io.ReadFull(r, buf)
47+
48+
// If the string table is large, the file may be corrupt.
49+
// Read in chunks to avoid crashing due to out of memory.
50+
const chunk = 10 << 20 // 10M
51+
var buf []byte
52+
if l < chunk {
53+
buf = make([]byte, l)
54+
_, err = io.ReadFull(r, buf)
55+
} else {
56+
for l > 0 {
57+
n := l
58+
if n > chunk {
59+
n = chunk
60+
}
61+
buf1 := make([]byte, n)
62+
_, err = io.ReadFull(r, buf1)
63+
if err != nil {
64+
break
65+
}
66+
buf = append(buf, buf1...)
67+
l -= n
68+
}
69+
}
4970
if err != nil {
5071
return nil, fmt.Errorf("fail to read string table: %v", err)
5172
}

0 commit comments

Comments
 (0)