Skip to content

Commit 4360777

Browse files
committed
debug/pe: validate the number of data directory entries
Updated file.go to validate the number of data directory entries before assuming the import data directory entry exists. This is not too common, but it _is_ possible so let's be defensive jic. debug/pe/file.go: validate NumberOfRvaAndSizes includes imports
1 parent 6dad9ee commit 4360777

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/debug/pe/file.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,21 @@ type ImportDirectory struct {
261261
func (f *File) ImportedSymbols() ([]string, error) {
262262
pe64 := f.Machine == IMAGE_FILE_MACHINE_AMD64
263263

264+
// grab the number of data directory entries
265+
var ddcount uint32
266+
if pe64 {
267+
ddcount = f.OptionalHeader.(*OptionalHeader64).NumberOfRvaAndSizes
268+
} else {
269+
ddcount = f.OptionalHeader.(*OptionalHeader32).NumberOfRvaAndSizes
270+
}
271+
272+
// if the import data directory doesn't actually exist then we can
273+
// assume that there's no symbols
274+
if ddcount < 2 {
275+
return nil, nil
276+
}
277+
278+
// grab the import data directory entry
264279
var idd DataDirectory
265280
if pe64 {
266281
idd = f.OptionalHeader.(*OptionalHeader64).DataDirectory[1]

0 commit comments

Comments
 (0)