From: Yann Collet Date: Thu, 12 Jan 2023 23:49:01 +0000 (-0800) Subject: add explanation about new test X-Git-Tag: v1.5.4^2~56^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ac45e078a5bc22e06d1be1375c25795b7ef3c1ff;p=thirdparty%2Fzstd.git add explanation about new test as requested by @terrelln --- diff --git a/lib/compress/zstd_compress_literals.c b/lib/compress/zstd_compress_literals.c index e84781873..0dbc2c4d4 100644 --- a/lib/compress/zstd_compress_literals.c +++ b/lib/compress/zstd_compress_literals.c @@ -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);