]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Fixed compressBound calculation for quick deflate strategy. Worse case is 9 bits...
authorNathan Moinvaziri <nathan@nathanm.com>
Fri, 6 Mar 2020 23:51:03 +0000 (15:51 -0800)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Fri, 13 Mar 2020 12:06:14 +0000 (13:06 +0100)
compress.c

index 5adcf653c202d5c9a705703a463edd9361788378..3c29ddea18dd11e25e3988921cdba4d1b79e48d2 100644 (file)
@@ -75,5 +75,11 @@ int ZEXPORT PREFIX(compress)(unsigned char *dest, z_size_t *destLen, const unsig
    this function needs to be updated.
  */
 z_size_t ZEXPORT PREFIX(compressBound)(z_size_t sourceLen) {
+#ifdef X86_QUICK_STRATEGY
+    /* Quick deflate strategy worse case is 9 bits per literal, rounded to nearest byte,
+       plus the size of block & gzip headers and footers */
+    return sourceLen + ((sourceLen + 13 + 7) >> 3) + 18;
+#else
     return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + (sourceLen >> 25) + 13;
+#endif
 }