Skip to content

Commit

Permalink
Fix bug resulting in not parsing all OPTIONAL_HEADER DataDirectory en…
Browse files Browse the repository at this point in the history
…tries

In the format for the PE optional header, the DataDirectory list has a fixed size of 16 address/size entries.
Previously, an incorrect assumption was made that the list of entries is dynamic and given by OPTIONAL_HEADER.NumberOfRvaAndSizes.
This resulted in only parsing the first entries in the list, which might not be the entries that are not empty.
The most extreme case of this was NumberOfRvaAndSizes being 6, and the first 6 data directories were all empty, so none of the directories with actual data were parsed.
  • Loading branch information
nightlark committed Dec 12, 2024
1 parent 4b3b1e2 commit feb8faa
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion pefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3267,7 +3267,7 @@ def __parse__(self, fname, data, fast_load):
)

MAX_ASSUMED_VALID_NUMBER_OF_RVA_AND_SIZES = 0x100
for i in range(int(0x7FFFFFFF & self.OPTIONAL_HEADER.NumberOfRvaAndSizes)):
for i in range(16):
if len(self.__data__) - offset == 0:
break

Expand Down

0 comments on commit feb8faa

Please sign in to comment.