summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMika Lindqvist <postmaster@raasu.org>2022-04-06 00:04:45 +0300
committerHans Kristian Rosbach <hk-github@circlestorm.org>2023-03-17 21:27:56 +0100
commitf9919acfc20bb068b1fad80fe81ea9a6446fc5ac (patch)
treedf55cfa6d4e86dfa23ec14293f1655840696081a
parent65c726b09fd5c18aa77600ff78b6c7878237dba9 (diff)
Add one extra byte to return value of compressBound and deflateBound for small lengths due to shift returning 0.
* Treat 0 byte input as 1 byte input when calculating compressBound and deflateBound
-rw-r--r--compress.c2
-rw-r--r--deflate.c2
2 files changed, 4 insertions, 0 deletions
diff --git a/compress.c b/compress.c
index fded2a4..1cf5d5f 100644
--- a/compress.c
+++ b/compress.c
@@ -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 */
diff --git a/deflate.c b/deflate.c
index 031a1bb..4c7e179 100644
--- 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 */