aboutsummaryrefslogtreecommitdiff
path: root/src/debug
diff options
context:
space:
mode:
Diffstat (limited to 'src/debug')
-rw-r--r--src/debug/pe/file.go18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/debug/pe/file.go b/src/debug/pe/file.go
index ed63a11cb6..91b7d1dca1 100644
--- a/src/debug/pe/file.go
+++ b/src/debug/pe/file.go
@@ -379,7 +379,11 @@ func (f *File) ImportedSymbols() ([]string, error) {
}
// seek to the virtual address specified in the import data directory
- d = d[idd.VirtualAddress-ds.VirtualAddress:]
+ seek := idd.VirtualAddress - ds.VirtualAddress
+ if seek >= uint32(len(d)) {
+ return nil, errors.New("optional header data directory virtual size doesn't fit within data seek")
+ }
+ d = d[seek:]
// start decoding the import directory
var ida []ImportDirectory
@@ -408,9 +412,16 @@ func (f *File) ImportedSymbols() ([]string, error) {
dt.dll, _ = getString(names, int(dt.Name-ds.VirtualAddress))
d, _ = ds.Data()
// seek to OriginalFirstThunk
- d = d[dt.OriginalFirstThunk-ds.VirtualAddress:]
+ seek := dt.OriginalFirstThunk - ds.VirtualAddress
+ if seek >= uint32(len(d)) {
+ return nil, errors.New("import directory original first thunk doesn't fit within data seek")
+ }
+ d = d[seek:]
for len(d) > 0 {
if pe64 { // 64bit
+ if len(d) < 8 {
+ return nil, errors.New("thunk parsing needs at least 8-bytes")
+ }
va := binary.LittleEndian.Uint64(d[0:8])
d = d[8:]
if va == 0 {
@@ -423,6 +434,9 @@ func (f *File) ImportedSymbols() ([]string, error) {
all = append(all, fn+":"+dt.dll)
}
} else { // 32bit
+ if len(d) <= 4 {
+ return nil, errors.New("thunk parsing needs at least 5-bytes")
+ }
va := binary.LittleEndian.Uint32(d[0:4])
d = d[4:]
if va == 0 {