diff options
| author | Mark Adler <git@madler.net> | 2026-01-04 10:34:44 -0600 |
|---|---|---|
| committer | Mark Adler <git@madler.net> | 2026-01-05 15:03:04 -0600 |
| commit | 916dc1ac351795c9bf86a3d19c3667b014b9d28e (patch) | |
| tree | 08efd9aa0c5387fe80c1ce15a9fdb0ca8e29c01c /compress.c | |
| parent | fd366384cf324d750596feb03be44ddf4d1e6acd (diff) | |
| download | zlib-916dc1ac351795c9bf86a3d19c3667b014b9d28e.tar.gz zlib-916dc1ac351795c9bf86a3d19c3667b014b9d28e.tar.bz2 zlib-916dc1ac351795c9bf86a3d19c3667b014b9d28e.zip | |
Add compressBound_z and deflateBound_z functions for large values.
These take and return size_t integers, instead of unsigned longs,
for those platforms with 32-bit longs. This commit also assures
that overflows of either integer type results in the maximum value
for that type, instead of wrapping to small values.
Diffstat (limited to 'compress.c')
| -rw-r--r-- | compress.c | 9 |
1 files changed, 7 insertions, 2 deletions
| @@ -69,7 +69,12 @@ int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source, | |||
| 69 | If the default memLevel or windowBits for deflateInit() is changed, then | 69 | If the default memLevel or windowBits for deflateInit() is changed, then |
| 70 | this function needs to be updated. | 70 | this function needs to be updated. |
| 71 | */ | 71 | */ |
| 72 | z_size_t ZEXPORT compressBound_z(z_size_t sourceLen) { | ||
| 73 | z_size_t bound = sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + | ||
| 74 | (sourceLen >> 25) + 13; | ||
| 75 | return bound < sourceLen ? (z_size_t)-1 : bound; | ||
| 76 | } | ||
| 72 | uLong ZEXPORT compressBound(uLong sourceLen) { | 77 | uLong ZEXPORT compressBound(uLong sourceLen) { |
| 73 | return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + | 78 | z_size_t bound = compressBound_z(sourceLen); |
| 74 | (sourceLen >> 25) + 13; | 79 | return (uLong)bound != bound ? (uLong)-1 : (uLong)bound; |
| 75 | } | 80 | } |
