Skip to content

Commit

Permalink
debug/pe: read string table in 10M chunks
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
ianlancetaylor authored and gopherbot committed Apr 15, 2022
1 parent df2421d commit 0c6d8bb
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/debug/pe/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,29 @@ func readStringTable(fh *FileHeader, r io.ReadSeeker) (StringTable, error) {
return nil, nil
}
l -= 4
buf := make([]byte, l)
_, err = io.ReadFull(r, buf)

// 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
}
}
if err != nil {
return nil, fmt.Errorf("fail to read string table: %v", err)
}
Expand Down

0 comments on commit 0c6d8bb

Please sign in to comment.