]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Add one extra byte to return value of compressBound and deflateBound for small length...
authorMika Lindqvist <postmaster@raasu.org>
Tue, 5 Apr 2022 21:04:45 +0000 (00:04 +0300)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Fri, 17 Mar 2023 20:27:56 +0000 (21:27 +0100)
* Treat 0 byte input as 1 byte input when calculating compressBound and deflateBound

compress.c
deflate.c

index fded2a4cdf65b37cd1d76e050c94a1c239da8f0e..1cf5d5ff108ec93701cb9902975b117c658a23cd 100644 (file)
@@ -92,6 +92,8 @@ z_size_t Z_EXPORT PREFIX(compressBound)(z_size_t sourceLen) {
 
 #ifndef NO_QUICK_STRATEGY
     return sourceLen                       /* The source size itself */
+      + (sourceLen == 0 ? 1 : 0)           /* Always at least one byte for any input */
+      + (sourceLen < 9 ? 1 : 0)            /* One extra byte for lengths less than 9 */
       + DEFLATE_QUICK_OVERHEAD(sourceLen)  /* Source encoding overhead, padded to next full byte */
       + DEFLATE_BLOCK_OVERHEAD             /* Deflate block overhead bytes */
       + ZLIB_WRAPLEN;                      /* zlib wrapper */
index 031a1bb086297a6ae7ff4ab116126c9b98a4b886..4c7e179eae678081ceabafb2bcf0816a9766359b 100644 (file)
--- a/deflate.c
+++ b/deflate.c
@@ -723,6 +723,8 @@ unsigned long Z_EXPORT PREFIX(deflateBound)(PREFIX3(stream) *strm, unsigned long
 
 #ifndef NO_QUICK_STRATEGY
     return sourceLen                       /* The source size itself */
+      + (sourceLen == 0 ? 1 : 0)           /* Always at least one byte for any input */
+      + (sourceLen < 9 ? 1 : 0)            /* One extra byte for lengths less than 9 */
       + DEFLATE_QUICK_OVERHEAD(sourceLen)  /* Source encoding overhead, padded to next full byte */
       + DEFLATE_BLOCK_OVERHEAD             /* Deflate block overhead bytes */
       + wraplen;                           /* none, zlib or gzip wrapper */