]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
[FSE] Fix division by zero
authorNick Terrell <terrelln@fb.com>
Sat, 28 Jul 2018 00:30:03 +0000 (17:30 -0700)
committerNick Terrell <terrelln@fb.com>
Sat, 28 Jul 2018 00:30:03 +0000 (17:30 -0700)
When the primary normalization method fails, and
`(1 << tableLog) == (maxSymbolValue + 1)`, and every symbol gets assigned
normalized weight 1 or -1 in the first loop, then the next division can
raise `SIGFPE`.

lib/compress/fse_compress.c

index 07b3ab89bd7c02e573377d2952cd8fbd9ed79227..95e7c1c7e749dc8f8567495c07533c3da4c73ba0 100644 (file)
@@ -394,6 +394,9 @@ static size_t FSE_normalizeM2(short* norm, U32 tableLog, const unsigned* count,
     }
     ToDistribute = (1 << tableLog) - distributed;
 
+    if (ToDistribute == 0)
+        return 0;
+
     if ((total / ToDistribute) > lowOne) {
         /* risk of rounding to zero */
         lowOne = (U32)((total * 3) / (ToDistribute * 2));