]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
[huf] Fix OSS-Fuzz assert 2808/head
authorNick Terrell <terrelln@fb.com>
Mon, 27 Sep 2021 20:56:07 +0000 (13:56 -0700)
committerNick Terrell <terrelln@fb.com>
Mon, 27 Sep 2021 20:56:07 +0000 (13:56 -0700)
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.

lib/decompress/huf_decompress.c

index 128b08019c480c536d717daf9b52f9e677c438db..7529034ef0a75678ac79f96f02aff120d9dd0229 100644 (file)
@@ -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 */