From: Nick Terrell Date: Mon, 27 Sep 2021 20:56:07 +0000 (-0700) Subject: [huf] Fix OSS-Fuzz assert X-Git-Tag: v1.5.1~1^2~89^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a07ddb47f7d43529dde4922786516f7ec14754cb;p=thirdparty%2Fzstd.git [huf] Fix OSS-Fuzz assert PR #2784 introduced a bug in the decompressor that caused some valid inputs to fail to decompress. The bitstream isn't reloaded after the 4X* loop if the number of elements remaining is small enough, causing us to read more bits than are available in the bitcontainer. This was caught by the MSAN fuzzer in OSS-Fuzz because the assembly implementation isn't used in the MSAN build. Credit to OSS-Fuzz. --- diff --git a/lib/decompress/huf_decompress.c b/lib/decompress/huf_decompress.c index 128b08019..7529034ef 100644 --- a/lib/decompress/huf_decompress.c +++ b/lib/decompress/huf_decompress.c @@ -531,6 +531,8 @@ HUF_decodeStreamX1(BYTE* p, BIT_DStream_t* const bitDPtr, BYTE* const pEnd, cons HUF_DECODE_SYMBOLX1_2(p, bitDPtr); HUF_DECODE_SYMBOLX1_0(p, bitDPtr); } + } else { + BIT_reloadDStream(bitDPtr); } /* [0-3] symbols remaining */ @@ -1218,6 +1220,8 @@ HUF_decodeStreamX2(BYTE* p, BIT_DStream_t* bitDPtr, BYTE* const pEnd, HUF_DECODE_SYMBOLX2_0(p, bitDPtr); } } + } else { + BIT_reloadDStream(bitDPtr); } /* closer to end : up to 2 symbols at a time */