]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
add explanation about new test 3419/head
authorYann Collet <cyan@fb.com>
Thu, 12 Jan 2023 23:49:01 +0000 (15:49 -0800)
committerYann Collet <cyan@fb.com>
Thu, 12 Jan 2023 23:49:01 +0000 (15:49 -0800)
as requested by @terrelln

lib/compress/zstd_compress_literals.c

index e8478187326f8eb495bc06098aff64af231769cd..0dbc2c4d4cd7b6eb1a20179e9c2fdb89b2f35f9a 100644 (file)
@@ -187,6 +187,11 @@ size_t ZSTD_compressLiterals (
             return ZSTD_noCompressLiterals(dst, dstCapacity, src, srcSize);
     }   }
     if (cLitSize==1) {
+        /* A return value of 1 signals that the alphabet consists of a single symbol.
+         * However, in some rare circumstances, it could be the compressed size (a single byte).
+         * For that outcome to have a chance to happen, it's necessary that `srcSize < 8`.
+         * (it's also necessary to not generate statistics).
+         * Therefore, in such a case, actively check that all bytes are identical. */
         if ((srcSize >= 8) || allBytesIdentical(src, srcSize)) {
             ZSTD_memcpy(nextHuf, prevHuf, sizeof(*prevHuf));
             return ZSTD_compressRleLiteralsBlock(dst, dstCapacity, src, srcSize);