Skip to content

Commit 1c5bd11

Browse files
committed
fix(pe): Avoid parsing an empty byte buffer
Prevent parsing the PE byte buffer if it is empty.
1 parent 095f0dc commit 1c5bd11

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

pkg/pe/parser.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ func ParseFileWithConfig(path string, config Config) (*PE, error) {
177177

178178
// ParseBytes tries to parse the PE from the given byte slice and parser options.
179179
func ParseBytes(data []byte, opts ...Option) (*PE, error) {
180+
if len(data) == 0 || va.Zeroed(data) {
181+
return nil, ErrEmptyVArea
182+
}
180183
return parse("", data, opts...)
181184
}
182185

@@ -195,9 +198,6 @@ func ParseMem(pid uint32, base uintptr, changeProtection bool, opts ...Option) (
195198
}
196199
defer windows.Close(process)
197200
area := va.ReadArea(process, base, MaxHeaderSize, MinHeaderSize, changeProtection)
198-
if len(area) == 0 || va.Zeroed(area) {
199-
return nil, ErrEmptyVArea
200-
}
201201
return ParseBytes(area, opts...)
202202
}
203203

0 commit comments

Comments
 (0)