eliben / pyelftools

Parsing ELF and DWARF in Python
Other
2.03k stars 512 forks source link

elftools: StringTableSection: Check table size before returning string #528

Open vapier opened 11 months ago

vapier commented 11 months ago

Some ELF files have strings pointing to an offset outside the string table dimension, let's throw an exception in that case.

Bug-Url: https://crbug.com/788925 Reviewed-on: https://chromium-review.googlesource.com/792553

sevaa commented 11 months ago

The second assert is unnecessary - parse_cstring_from_stream will not read past the end of the stream (this ain't C, people). If there is indeed an unterminated string at the end of the section, parse_cstring_from_stream will return None and the expression in the assert will throw an exception that you are calling len() on a None object.

Remove the second check, it's pointless and wrong.

sevaa commented 7 months ago

@vapier Are you still interested in this change?

sevaa commented 2 months ago

Now that I look at it, should we really spend time on providing descriptive exceptions for various flavors of corrupt data? As things stand right now, pyelftools will exception on a file with a string offset leading to nowhere (decode called on NoneType will be the exception); with this patch, the exception will be more descriptive. On one hand, that's a user friendly thing to do; on the other hand, given the myriad ways an extremely interlinked data structure can be corrupt, should we endeavor to catalogue them all?