Repository navigation
[libzstd] Fix infinite loop in decompression - #1446
Conversation
|
Thanks for catching that issue. So the scenario proves that it's not possible to blindly add It's worth noting that we have another problem, if the skippable frame size is Making all constant In all instances I could find, the result of the addition is saved into a However, the result of the addition will still be incorrect in 32-bit mode. Alternatively, it could also make sense to just reject such sizes, and return an error code instead. For discussion |
Cyan4973
left a comment
There was a problem hiding this comment.
blindly casting constants to ULL is an issue for 32-bit builds
|
Looks like this fix doesn't work on 32-bit platforms. |
When we switched `ZSTD_SKIPPABLEHEADERSIZE` to a macro, the places where we do:
MEM_readLE32(ptr) + ZSTD_SKIPPABLEHEADERSIZE
can now overflow `(unsigned)-8` to `0` and we infinite loop. We now check
the frame size and reject sizes that overflow a U32.
Note that this bug never made it into a release, and was only in the dev branch
for a few days.
Credit to OSS-Fuzz
|
I've switched to checking for overflow. |
When we switched
ZSTD_SKIPPABLEHEADERSIZEto a macro, the places where we do:can now overflow
(unsigned)-8to0and we infinite loop. The fix is to makethe variable an
unsigned long long, so it is always 64-bits. I've also madethe other related variables
unsigned long longto mitigate similar potentialissues.
Note that this bug never made it into a release, and was only in the dev branch
for a few days.
Credit to OSS-Fuzz