vstinner / hachoir

Hachoir is a Python library to view and edit a binary stream field by field
http://hachoir.readthedocs.io/
GNU General Public License v2.0
613 stars 70 forks source link

Set size of truncated JpegImageData to rest of stream #68

Closed cccs-jh closed 3 years ago

cccs-jh commented 3 years ago

Suggested fix for #67.

Set the size of an JpegImageData section with no terminator to the remainder of the stream, on the assumption that the file is truncated in the middle of the JpegImageData and so the rest of the file is its data. This avoids the JpegImageData being parsed to calculate it's size, and hopefully prevents the corrupted section needing to be parsed at all for most operations.

If the JpegImageData is explicitly parsed the memory blowup and parsing errors will still happen, but that seems like the expected outcome of parsing a large corrupt section rather than a surprise that happens when checking for fields.

vstinner commented 3 years ago

The fix LGTM.