]> git.ipfire.org Git - thirdparty/zstd.git/commit
fix root cause of #3416
authorYann Collet <cyan@fb.com>
Wed, 11 Jan 2023 23:11:51 +0000 (15:11 -0800)
committerYann Collet <cyan@fb.com>
Thu, 12 Jan 2023 23:41:08 +0000 (15:41 -0800)
commit796699c0bc12ae1efa405418b14cb6dd0101cc6f
treeae8b5ad4b6761d3a23161f13b6c08f1f1c615ff9
parent423500d1ae0c4aa5bff90c1106324ef963434667
fix root cause of #3416

A minor change in 5434de0 changed a `<=` into a `<`,
and as an indirect consequence allowed compression attempt of literals when there are only 6 literals to compress
(previous limit was effectively 7 literals).

This is not in itself a problem, as the threshold is merely an heuristic,
but it emerged a bug that has always been there, and was just never triggered so far due to the previous limit.
This bug would make the literal compressor believes that all literals are the same symbol,
but for the exact case where nbLiterals==6, plus a pretty wild combination of other limit conditions,
this outcome could be false, resulting in data corruption.

Replaced the blind heuristic by an actual test for all limit cases,
so that even if the threshold is changed again in the future,
the detection of RLE mode will remain reliable.
lib/common/huf.h
lib/compress/huf_compress.c
lib/compress/zstd_compress_literals.c
lib/compress/zstd_compress_literals.h
lib/decompress/zstd_decompress.c