Commit 6c37c10f authored by Adenilson Cavalcanti's avatar Adenilson Cavalcanti Committed by Commit Bot

Increasing the expected compressed output size

Usage of CRC32 Castagnoli as a hash function for the hash table of symbols
used for compression has a side effect where for compression level [4, 5]
it will increase the required output buffer size by 0.1% (i.e. less than 1%)
for a high entropy input (i.e. random data).

To avoid a scenario where client code would fail while compressing data,
this patch will increase the compressBound by 0.8% (i.e. 8x than worst
case scenario).

Validated using zlib_bench with the data from the 'Random Compression
Challenge' on both Intel and Arm.

Bug: 990489
Change-Id: I86c6ab09fce6ab09b45c502221864400b86a7d80
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1733790
Commit-Queue: Adenilson Cavalcanti <cavalcantii@chromium.org>
Reviewed-by: default avatarChris Blume <cblume@chromium.org>
Reviewed-by: default avatarAdenilson Cavalcanti <cavalcantii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#684170}
parent 28032e00
...@@ -81,6 +81,16 @@ int ZEXPORT compress (dest, destLen, source, sourceLen) ...@@ -81,6 +81,16 @@ int ZEXPORT compress (dest, destLen, source, sourceLen)
uLong ZEXPORT compressBound (sourceLen) uLong ZEXPORT compressBound (sourceLen)
uLong sourceLen; uLong sourceLen;
{ {
return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + sourceLen = sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
(sourceLen >> 25) + 13; (sourceLen >> 25) + 13;
/* FIXME(cavalcantii): usage of CRC32 Castagnoli as a hash function
* for the hash table of symbols used for compression has a side effect
* where for compression level [4, 5] it will increase the output buffer size
* by 0.1% (i.e. less than 1%) for a high entropy input (i.e. random data).
* To avoid a scenario where client code would fail, for safety we increase
* the expected output size by 0.8% (i.e. 8x more than the worst scenario).
* See: http://crbug.com/990489
*/
sourceLen += sourceLen >> 7; // Equivalent to 1.0078125
return sourceLen;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment