Fix invalid assert in 32-bit decoding

The assert is only correct for valid sequences, so disable it for
everything execpt round trip fuzzers.
This commit is contained in:
Nick Terrell 2023-01-27 11:14:56 -08:00 committed by Nick Terrell
parent 423a74986f
commit b3b43f2893

View File

@ -1241,7 +1241,13 @@ ZSTD_decodeSequence(seqState_t* seqState, const ZSTD_longOffset_e longOffsets)
offset = ofBase + (BIT_readBitsFast(&seqState->DStream, ofBits - extraBits) << extraBits);
BIT_reloadDStream(&seqState->DStream);
if (extraBits) offset += BIT_readBitsFast(&seqState->DStream, extraBits);
#if defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION) && defined(FUZZING_ASSERT_VALID_SEQUENCE)
/* This assert is only valid when decoding valid sequences.
* It cal fail when we consume more bits than are in the bitstream,
* which can happen on corruption.
*/
assert(extraBits <= LONG_OFFSETS_MAX_EXTRA_BITS_32); /* to avoid another reload */
#endif
} else {
offset = ofBase + BIT_readBitsFast(&seqState->DStream, ofBits/*>0*/); /* <= (ZSTD_WINDOWLOG_MAX-1) bits */
if (MEM_32bits()) BIT_reloadDStream(&seqState->DStream);