]> 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, 22 Apr 2022 11:50:22 +0000 (13:50 +0200)
* Treat 0 byte input as 1 byte input when calculating compressBound and deflateBound

compress.c
deflate.c

index db13f6ca22c0c37c9dfb8926c5acf263cb4cb789..44f8dd9eb3d8b1e092e25530ad068141c110306c 100644 (file)
@@ -87,6 +87,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 50c5531f1bb7c19781914a14adca36537898726d..233a629c42b7e2cbe8578adc6fafc13bd3c5fa2e 100644 (file)
--- a/deflate.c
+++ b/deflate.c
@@ -646,6 +646,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 */