Skip to content

Commit 9b26dcb

Browse files
committed
debug/pe: fix OOM caused by huge NumberOfSymbols
Creating a new PE file with `NewFile()` in package `debug/pe` would meet out-of0memory if `NumberOfSymbols` field of `COFFSymbol` struct is a huge value. A fixed limit is set to fix this problem. If `NumberOfSymbols` excesses this limit, then an error is returned to notify this. The limit allows PE file which owns a 72MB symbol table in maximum Fixes #43827
1 parent 928bda4 commit 9b26dcb

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/debug/pe/symbol.go

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ func readCOFFSymbols(fh *FileHeader, r io.ReadSeeker) ([]COFFSymbol, error) {
3333
if err != nil {
3434
return nil, fmt.Errorf("fail to seek to symbol table: %v", err)
3535
}
36+
37+
if fh.NumberOfSymbols > (1 << 22) {
38+
return nil, fmt.Errorf("fail to seek to symbol table: NumberOfSymbols field is too huge")
39+
}
3640
syms := make([]COFFSymbol, fh.NumberOfSymbols)
3741
err = binary.Read(r, binary.LittleEndian, syms)
3842
if err != nil {

0 commit comments

Comments
 (0)