Skip to content

Commit 3013acb

Browse files
randomasciiChromium LUCI CQ
authored and
Chromium LUCI CQ
committed
Increase arbitrary offset limit in pefile.py
In an attempt to detect corrupt files pefile.py imposes an arbitrary maximum offset of 0x10000000 (256 MiB). However Chrome's dcheck official builds exceed that limit which means that uploading of symbols started failing. This change increases the limit to 1 GiB. An issue has been filed against the pefile project for a long-term fix but this fix will unblock dcheck official builds for now. erocarrera/pefile#396 Bug: 329661971 Change-Id: Ica4905a61216a11e4ad56734977582133bc26684 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5377931 Commit-Queue: Bruce Dawson <[email protected]> Reviewed-by: Alex Gough <[email protected]> Cr-Commit-Position: refs/heads/main@{#1274350}
1 parent 7e70d95 commit 3013acb

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

third_party/pefile_py3/README.chromium

+2
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ headers is accessible, as well as all the sections' details and data.
1616
Local Modifications:
1717
- Only pefile.py, ordlookup, and LICENSE are present.
1818
- BUILD.gn, OWNERS, and README.chromium files were added.
19+
- pefile.py patched to increase the 0x10000000 offset limit for
20+
https://crbug.com/329661971.

third_party/pefile_py3/pefile.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ def count_zeroes(data):
138138
# Limit number of exported symbols
139139
MAX_SYMBOL_EXPORT_COUNT = 0x2000
140140

141+
# Arbitrary maximum offset to detect suspicious/bogus files.
142+
MAX_OFFSET = 0x40000000
143+
141144
IMAGE_DOS_SIGNATURE = 0x5A4D
142145
IMAGE_DOSZM_SIGNATURE = 0x4D5A
143146
IMAGE_NE_SIGNATURE = 0x454E
@@ -2430,16 +2433,16 @@ def parse_sections(self, offset):
24302433
self.__warnings.append(
24312434
'Error parsing section {0}. PointerToRawData points beyond the end of the file.'.format(i))
24322435

2433-
if section.Misc_VirtualSize > 0x10000000:
2436+
if section.Misc_VirtualSize > MAX_OFFSET:
24342437
simultaneous_errors += 1
24352438
self.__warnings.append(
2436-
'Suspicious value found parsing section {0}. VirtualSize is extremely large > 256MiB.'.format(i))
2439+
'Suspicious value found parsing section {0}. VirtualSize is extremely large > {1}.'.format(i, MAX_OFFSET))
24372440

24382441
if self.adjust_SectionAlignment( section.VirtualAddress,
2439-
self.OPTIONAL_HEADER.SectionAlignment, self.OPTIONAL_HEADER.FileAlignment ) > 0x10000000:
2442+
self.OPTIONAL_HEADER.SectionAlignment, self.OPTIONAL_HEADER.FileAlignment ) > MAX_OFFSET:
24402443
simultaneous_errors += 1
24412444
self.__warnings.append(
2442-
'Suspicious value found parsing section {0}. VirtualAddress is beyond 0x10000000.'.format(i))
2445+
'Suspicious value found parsing section {0}. VirtualAddress is beyond {1}.'.format(i, MAX_OFFSET))
24432446

24442447
if ( self.OPTIONAL_HEADER.FileAlignment != 0 and
24452448
( section.PointerToRawData % self.OPTIONAL_HEADER.FileAlignment) != 0):
@@ -4397,7 +4400,7 @@ def get_import_table(self, rva, max_length=None, contains_addresses=False):
43974400
return table
43984401

43994402

4400-
def get_memory_mapped_image(self, max_virtual_address=0x10000000, ImageBase=None):
4403+
def get_memory_mapped_image(self, max_virtual_address=MAX_OFFSET, ImageBase=None):
44014404
"""Returns the data corresponding to the memory layout of the PE file.
44024405
44034406
The data includes the PE header and the sections loaded at offsets

0 commit comments

Comments
 (0)