temisu / ancient

Decompression routines for ancient formats
BSD 2-Clause "Simplified" License
209 stars 15 forks source link

Possible speed improvement for PMC files #78

Closed sagamusix closed 4 months ago

sagamusix commented 4 months ago

PMC files with additional delta encoding can cause slow decoding with some malformed files like this one: id%3A000068,src%3A000370,time%3A12372812415,execs%3A7946655230,op%3Ahavoc,rep%3A5.zip

The LH decompressor chickens out very quickly, but since there is no communication about the incomplete decompression, the delta step will process the entire output stream. If a PMC file claims to have a very large output (several hundred MB) but is only a few bytes large, the delta step will dominate the time to unpack the file. Maybe this could be improved so that the delta step only processes as much data as has been unpacked.

temisu commented 4 months ago

Well, short streams are legitimate in the lh.library, thus they can't be immediately ruled out.

I simplified the processing and reduced the limits to allow only 128M files, which still should be plenty.

But yeah. Fuzzing found a real decompression bomb