sashs / filebytes

Library to read and edit files in the following formats: Executable and Linking Format (ELF), Portable Executable (PE), MachO and OAT (Android Runtime)
https://scoding.de/filebytes-introduction
BSD 3-Clause "New" or "Revised" License
126 stars 25 forks source link

regression in mach_o.py (OverflowError: cannot fit 'int' into an index-sized integer) #2

Closed anthraxx closed 8 years ago

anthraxx commented 8 years ago

I noticed this bug while trying to package ropper 1.8.0 via the ropper test suite https://github.com/sashs/Ropper/issues/18. Please also maybe consider adding some unit tests for this project directly to make it able to test for regressions before any release.

PS: the tests were running on i686 (32bit) because of the packaging process

ERROR: test_gadgets (testcases.test_x86_64.MACHO_x86_84)

Traceback (most recent call last): File "/build/ropper/src/Ropper-1.8.0/testcases/test_x86_64.py", line 132, in setUp self.file = Loader.open('test-binaries/ls-macho-x86_64') File "/build/ropper/src/Ropper-1.8.0/ropper/loaders/loader.py", line 154, in open return subclass(fileName) File "/build/ropper/src/Ropper-1.8.0/ropper/loaders/mach_o.py", line 33, in init super(MachO, self).init(filename) File "/build/ropper/src/Ropper-1.8.0/ropper/loaders/loader.py", line 72, in init self.binary = self._loadFile(filename) File "/build/ropper/src/Ropper-1.8.0/ropper/loaders/mach_o.py", line 92, in _loadFile return macho.MachO(fileName) File "/usr/lib/python3.5/site-packages/filebytes/mach_o.py", line 328, in __init self.loadCommands = self._parseLoadCommands(self._bytes, self.machHeader) File "/usr/lib/python3.5/site-packages/filebytes/mach_o.py", line 384, in _parseLoadCommands command = self.parseSegmentCommand(data, offset, raw) File "/usr/lib/python3.5/site-packages/filebytes/mach_o.py", line 404, in parseSegmentCommand sections = self.parseSections(data, sc, offset+sizeof(self._classes.SegmentCommand)) File "/usr/lib/python3.5/site-packages/filebytes/mach_o.py", line 442, in __parseSections raw = (c_ubyte * sec.size).from_buffer(data, sec.offset) OverflowError: cannot fit 'int' into an index-sized integer

ERROR: test_general (testcases.test_x86_64.MACHO_x86_84)

Traceback (most recent call last): File "/build/ropper/src/Ropper-1.8.0/testcases/test_x86_64.py", line 132, in setUp self.file = Loader.open('test-binaries/ls-macho-x86_64') File "/build/ropper/src/Ropper-1.8.0/ropper/loaders/loader.py", line 154, in open return subclass(fileName) File "/build/ropper/src/Ropper-1.8.0/ropper/loaders/mach_o.py", line 33, in init super(MachO, self).init(filename) File "/build/ropper/src/Ropper-1.8.0/ropper/loaders/loader.py", line 72, in init self.binary = self._loadFile(filename) File "/build/ropper/src/Ropper-1.8.0/ropper/loaders/mach_o.py", line 92, in _loadFile return macho.MachO(fileName) File "/usr/lib/python3.5/site-packages/filebytes/mach_o.py", line 328, in __init self.loadCommands = self._parseLoadCommands(self._bytes, self.machHeader) File "/usr/lib/python3.5/site-packages/filebytes/mach_o.py", line 384, in _parseLoadCommands command = self.parseSegmentCommand(data, offset, raw) File "/usr/lib/python3.5/site-packages/filebytes/mach_o.py", line 404, in parseSegmentCommand sections = self.parseSections(data, sc, offset+sizeof(self._classes.SegmentCommand)) File "/usr/lib/python3.5/site-packages/filebytes/mach_o.py", line 442, in __parseSections raw = (c_ubyte * sec.size).from_buffer(data, sec.offset) OverflowError: cannot fit 'int' into an index-sized integer

ERROR: test_jmpreg (testcases.test_x86_64.MACHO_x86_84)

Traceback (most recent call last): File "/build/ropper/src/Ropper-1.8.0/testcases/test_x86_64.py", line 132, in setUp self.file = Loader.open('test-binaries/ls-macho-x86_64') File "/build/ropper/src/Ropper-1.8.0/ropper/loaders/loader.py", line 154, in open return subclass(fileName) File "/build/ropper/src/Ropper-1.8.0/ropper/loaders/mach_o.py", line 33, in init super(MachO, self).init(filename) File "/build/ropper/src/Ropper-1.8.0/ropper/loaders/loader.py", line 72, in init self.binary = self._loadFile(filename) File "/build/ropper/src/Ropper-1.8.0/ropper/loaders/mach_o.py", line 92, in _loadFile return macho.MachO(fileName) File "/usr/lib/python3.5/site-packages/filebytes/mach_o.py", line 328, in __init self.loadCommands = self._parseLoadCommands(self._bytes, self.machHeader) File "/usr/lib/python3.5/site-packages/filebytes/mach_o.py", line 384, in _parseLoadCommands command = self.parseSegmentCommand(data, offset, raw) File "/usr/lib/python3.5/site-packages/filebytes/mach_o.py", line 404, in parseSegmentCommand sections = self.parseSections(data, sc, offset+sizeof(self._classes.SegmentCommand)) File "/usr/lib/python3.5/site-packages/filebytes/mach_o.py", line 442, in __parseSections raw = (c_ubyte * sec.size).from_buffer(data, sec.offset) OverflowError: cannot fit 'int' into an index-sized integer

ERROR: test_ppr (testcases.test_x86_64.MACHO_x86_84)

Traceback (most recent call last): File "/build/ropper/src/Ropper-1.8.0/testcases/test_x86_64.py", line 132, in setUp self.file = Loader.open('test-binaries/ls-macho-x86_64') File "/build/ropper/src/Ropper-1.8.0/ropper/loaders/loader.py", line 154, in open return subclass(fileName) File "/build/ropper/src/Ropper-1.8.0/ropper/loaders/mach_o.py", line 33, in init super(MachO, self).init(filename) File "/build/ropper/src/Ropper-1.8.0/ropper/loaders/loader.py", line 72, in init self.binary = self._loadFile(filename) File "/build/ropper/src/Ropper-1.8.0/ropper/loaders/mach_o.py", line 92, in _loadFile return macho.MachO(fileName) File "/usr/lib/python3.5/site-packages/filebytes/mach_o.py", line 328, in __init self.loadCommands = self._parseLoadCommands(self._bytes, self.machHeader) File "/usr/lib/python3.5/site-packages/filebytes/mach_o.py", line 384, in _parseLoadCommands command = self.parseSegmentCommand(data, offset, raw) File "/usr/lib/python3.5/site-packages/filebytes/mach_o.py", line 404, in parseSegmentCommand sections = self.parseSections(data, sc, offset+sizeof(self._classes.SegmentCommand)) File "/usr/lib/python3.5/site-packages/filebytes/mach_o.py", line 442, in __parseSections raw = (c_ubyte * sec.size).from_buffer(data, sec.offset) OverflowError: cannot fit 'int' into an index-sized integer


Ran 35 tests in 64.721s

FAILED (errors=4)

sashs commented 8 years ago

Hi,

I test it again. This error only happens on a 32bit system. I will look at that. Yes I will add tests for this package as well. :)

sashs commented 8 years ago

Should be fixed now. Could you test it, please?

anthraxx commented 8 years ago

works, thx :+1: