diff options
author | Mika Lindqvist <postmaster@raasu.org> | 2022-04-06 00:04:45 +0300 |
---|---|---|
committer | Hans Kristian Rosbach <hk-github@circlestorm.org> | 2023-03-17 21:27:56 +0100 |
commit | f9919acfc20bb068b1fad80fe81ea9a6446fc5ac (patch) | |
tree | df55cfa6d4e86dfa23ec14293f1655840696081a | |
parent | 65c726b09fd5c18aa77600ff78b6c7878237dba9 (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.c | 2 | ||||
-rw-r--r-- | deflate.c | 2 |
2 files changed, 4 insertions, 0 deletions
@@ -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 */ @@ -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 */ |