-
Notifications
You must be signed in to change notification settings - Fork 511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parsing error elftools.common.exceptions.ELFParseError: expected 4, found 0
#367
Comments
It would be easier for the community to troubleshoot it if the OP did the fundamental legwork of hand parsing the sample. Specifically, what's that file like in hex, and how does that map to the ELF header structures. From looking at the Base64 representation, it's not immediately obvious that the ELF is well formed and pyelftools is to blame. |
Hi @sevaa , thank you for your reaction. Ultimately, can somebody help fix this, please ? |
Readelf is telling you that the file is not well formed:
The readelf output suggests that the ELF header claims 5 sections in file. That field is the 2 byte value at 0x30. There is indeed 5. That means there should be a section header table. Meanwhile, there is no such thing. Pyelftools tells you the same by throwing an exception (maybe with less details :)). To me, that suggests the problem is not with pyelftools, it's with the file. Where did you get this file data in the first place? It looks like the beginning of a larger, valid ELF file with the end cut off. The ELF format doesn't allow for that. Even XML with the end cut off stops being valid. :) There is no criticism, only advice regarding the expectations. Please note this is the issue tracker specifically for pyelftools, not a general purpose forum devoted to ELF parsing (that would be StackOverflow :)). If you are creating an issue here, you are saying something is wrong with pyelftools. That's how issue trackers work. The burden of proof that pyelftools is indeed working incorrectly is on you. If your issue is that the error message of the exception that pyelftools is throwing on this particular malformed file is not sufficiently descriptive, please say so. Pyelftools throwing an exception on a bad ELF file is not a bug. |
Where did you get this file data in the first place? That was the right question to raise ;-) So, in pyelftools, shoudn't it be a simple warning instead of an exception ? |
The final sentence of that page's preamble says:
The file's author freely admits it's malformed. The fact that the ELF loader in Ubuntu Linux forgives this particular deviation from the format is an undocumented implementation detail. In a future version of Linux, they might remove this loophole.
As a general rule, parser libraries are not expected to gracefully handle data that don't conform to the format. They throw exceptions instead. On a side note, how exactly do you expect pyelftools to "do a warning"? |
Thanks for helping investigate this, @sevaa Seems like it's WAI. |
WAI ?... |
Works As Intended. |
OK, my bad. |
This fixes segfault on ELFs with malformed section headers (sh_name), such as one from eliben/pyelftools#367
* BinaryInfo: ensure sh_name lies within file This fixes segfault on ELFs with malformed section headers (sh_name), such as one from eliben/pyelftools#367 * BinaryInfo: fix FPE: division by 0 crash when sh_entsize == 0 A crash may happen on malformed ELFs when a section of either SHT_RELA or SHT_REL or SHT_DYNSYM type has sh_entsize == 0.
I get an error when trying to parse a simple hello-world ELF.
Steps to reproduce:
The text was updated successfully, but these errors were encountered: