Closed echel0nn closed 1 year ago
Um, how is it a bug if the library throws an exception on a malformed file? There are many ways a complex format like ELF can be malformed, and introducing a special case for each would be unfeasible. Now, readelf.py, being an interactive piece rather than a library, would do well to catch the exception and display a friendly error message, but a parser library is under no obligation to work around bogus content (unless it's known to be the kind emitted by a popular toolchain :). That said, descriptions.py
is pretty much the back-end of readelf.py rather than a part of the parser proper. Tricky case, I guess. Let @eliben decide :)
yes, when I think about it again, the idea I mentioned is very shallow and very specific case:) yet I still opened an issue because I thought that it should not prevent readelf.py to continue even if keyerror is not handled directly.
Yes, throwing an exception is fine in this case.
Describe the Bug
Eventhough e_version is mostly ignored by the Linux loader, A malicious ELF File with malformed e_version value which can prevent itself from being analyzed (if pyelftools is in-use for it).
To Reproduce
1) A dummy file with ELF format and malformed e_version.
2) run with
readelf.py -e sample.bin
Expected Behaviour
Parse e_version value, return "unknown" if it's not a regular value.
Environment
Linux 6.2.10-zen1-1-zen x86_64 GNU/Linux, Python 3.10.10, pyelftools:git/master
readelf.py
Additional Comments
elf/descriptions.py
and
I can create a PR, if the possible fix seems okay. After fix: