Commit Graph

143 Commits

Author SHA1 Message Date
Mark Adler 3adaa095a7 One more correction for deflateUsed() bits in stored case. 2024-07-05 23:04:59 -05:00
Mark Adler 884e0c0809 Correct used bits from deflateUsed() for deflate_stored() case. 2024-07-05 00:48:56 -05:00
Mark Adler e011d8c164 Add deflateUsed() function to get the used bits in the last byte.
This returns the number of used bits in the last byte of a stream
that has just been compressed with deflate.
2024-07-01 19:34:40 -05:00
Mark Adler a8c321be84 Make deflateBound() more conservative and handle Z_STREAM_END. 2024-03-09 23:53:37 -08:00
Mark Adler 7a7202de35 Correct a variable type in deflate.c. 2024-02-09 20:11:18 -08:00
Levi Broderick 8a76f02e0e Avoid implicit conversion warnings in deflate.c and trees.c. 2024-01-23 08:45:00 -08:00
Mark Adler 9f0f2d4f9f Change version number on develop branch to 1.3.1.1. 2024-01-22 13:07:41 -08:00
Mark Adler 51b7f2abda zlib 1.3.1 2024-01-22 10:32:37 -08:00
Mark Adler 7af6320ad7 Fix a bug in ZLIB_DEBUG compiles in check_match().
This avoids trying to compare a match starting one byte before the
current window. Thanks to @zmodem (Hans) for discovering this.
2024-01-19 12:19:53 -08:00
Hans Wennborg 60c31985ec Fix the copy of pending_buf in deflateCopy() for the LIT_MEM case. 2024-01-13 22:30:30 -08:00
Mark Adler ac8f12c97d Add LIT_MEM define to use more memory for a small deflate speedup.
A bug fix in zlib 1.2.12 resulted in a slight slowdown (1-2%) of
deflate. This commit provides the option to #define LIT_MEM, which
uses more memory to reverse most of that slowdown. The memory for
the pending buffer and symbol buffers is increased by 25%, which
increases the total memory usage with the default parameters by
about 6%.
2023-09-21 00:14:56 -07:00
Mark Adler 3a98b57e55 Change version number on develop branch to 1.3.0.1. 2023-08-18 13:23:07 -07:00
Mark Adler 09155eaa2f zlib 1.3 2023-08-18 01:45:36 -07:00
Andrzej Hunt 981ee7570a Suppress MSAN detections in deflate's slide_hash().
slide_hash() knowingly reads potentially uninitialized memory, see
comment lower down about prev[n] potentially being garbage. In
this case, the result is never used.
2023-08-12 13:15:21 -07:00
Mark Adler e9d5486e66 Remove K&R function definitions from zlib.
C2X has removed K&R definitions from the C function syntax.
Though the standard has not yet been approved, some high-profile
compilers are now issuing warnings when such definitions are
encountered.
2023-04-15 21:17:31 -07:00
Mark Adler e554695638 Fix bug in deflateBound() for level 0 and memLevel 9.
memLevel 9 would cause deflateBound() to assume the use of fixed
blocks, even if the compression level was 0, which forces stored
blocks. That could result in a bound less than the size of the
compressed data. Now level 0 always uses the stored blocks bound.
2022-12-15 09:15:31 -08:00
Mark Adler 41fda48fc2 Change version number on develop branch to 1.2.13.1. 2022-10-15 09:02:21 -07:00
Mark Adler 04f42ceca4 zlib 1.2.13 2022-10-12 22:06:55 -07:00
Mark Adler a9e14e8541 Avoid undefined negation behavior if windowBits is INT_MIN. 2022-10-06 20:43:18 -07:00
Mark Adler d0704a8201 Remove deleted assembler code references.
The code was removed, but the builds that used the code were not
updated. This fixes that. Thanks to Adenilson and toxieainc for
the patches.
2022-10-06 20:43:09 -07:00
Mark Adler 84c6716a48 Minor formatting improvements.
No code changes.
2022-10-05 15:17:52 -07:00
Mark Adler 4078713e3b Tighten deflateBound bounds.
This improves the non-default expansion from 14% down to 4% in
most cases, and 13% in the remainder.
2022-10-05 15:16:42 -07:00
Mark Adler 5752b171fd Fix some typos.
No code changes.
2022-08-23 15:35:13 -07:00
Mark Adler a4c17581d8 Change version number on develop branch to 1.2.12.1. 2022-03-27 18:07:49 -07:00
Mark Adler 21767c654d zlib 1.2.12 2022-03-27 16:05:02 -07:00
Mark Adler 4346a16853 Assure that the number of bits for deflatePrime() is valid. 2018-04-19 19:47:53 -07:00
Mark Adler 5c44459c3b Fix a bug that can crash deflate on some input when using Z_FIXED.
This bug was reported by Danilo Ramos of Eideticom, Inc. It has
lain in wait 13 years before being found! The bug was introduced
in zlib 1.2.2.2, with the addition of the Z_FIXED option. That
option forces the use of fixed Huffman codes. For rare inputs with
a large number of distant matches, the pending buffer into which
the compressed data is written can overwrite the distance symbol
table which it overlays. That results in corrupted output due to
invalid distances, and can result in out-of-bound accesses,
crashing the application.

The fix here combines the distance buffer and literal/length
buffers into a single symbol buffer. Now three bytes of pending
buffer space are opened up for each literal or length/distance
pair consumed, instead of the previous two bytes. This assures
that the pending buffer cannot overwrite the symbol table, since
the maximum fixed code compressed length/distance is 31 bits, and
since there are four bytes of pending space for every three bytes
of symbol space.
2018-04-19 19:47:11 -07:00
Mark Adler c376a417a7 Fix deflateEnd() to not report an error at start of raw deflate. 2017-10-12 21:07:22 -07:00
Mark Adler 38e8ce32af Fix CLEAR_HASH macro to be usable as a single statement.
As it is used in deflateParams().
2017-02-15 22:39:26 -08:00
Mark Adler 8ba393e70d Fix bug when window full in deflate_stored(). 2017-02-15 22:39:25 -08:00
Mark Adler 2d80d3f6b5 Limit hash table inserts after switch from stored deflate.
This limits hash table inserts to the available data in the window
and to the sliding window size in deflate_stored(). The hash table
inserts are deferred until deflateParams() switches to a non-zero
compression level.
2017-02-15 22:39:25 -08:00
Mark Adler f9694097dd Permit a deflateParams() parameter change as soon as possible.
This commit allows a parameter change even if the input data has
not all been compressed and copied to the application output
buffer, so long as all of the input data has been compressed to
the internal pending output buffer. This also allows an immediate
deflateParams change so long as there have been no deflate calls
since initialization or reset.
2017-02-15 22:38:55 -08:00
Mark Adler 7d60b86782 Change version number to 1.2.11.1. 2017-01-15 22:46:03 -08:00
Mark Adler cacf7f1d4e zlib 1.2.11 2017-01-15 09:29:40 -08:00
Mark Adler cbbd20302c Permit immediate deflateParams changes before any deflate input.
This permits deflateParams to change the strategy and level right
after deflateInit, without having to wait until a header has been
written. The parameters can be changed immediately up until the
first deflate call that consumes any input data.
2017-01-15 09:29:40 -08:00
Mark Adler 7d9c9d410a Update high water mark in deflate_stored.
This avoids unnecessary filling of bytes in the sliding window
buffer when switching from level zero to a non-zero level. This
also provides a consistent indication of deflate having taken
input for a later commit ...
2017-01-15 09:29:27 -08:00
Mark Adler 4c7c907683 Fix deflate stored bug when pulling last block from window.
And some cosmetic cleanups.
2017-01-15 09:07:14 -08:00
Mark Adler 11ceaed751 Change version number to 1.2.10.1. 2017-01-15 09:07:08 -08:00
Mark Adler 4a090adef8 zlib 1.2.10 2017-01-02 18:21:29 -08:00
Mark Adler 1e3bccd496 Add warnings when compiling with assembler code.
There have been many reports of bugs in the assembler codes
intended to speed up deflate and inflate. They are third-party
contributions in contrib, and so are not supported by the zlib
maintainers.
2017-01-02 17:28:27 -08:00
Mark Adler bc5503b224 Fix bug in deflate_stored() for zero-length input. 2017-01-02 15:17:59 -08:00
Mark Adler 20e472546e Change version number to zlib 1.2.9.1. 2017-01-01 22:24:17 -08:00
Mark Adler 2fa463bacf zlib 1.2.9 2016-12-31 23:37:10 -08:00
Mark Adler 8f147c3d12 Avoid some random compiler warnings on various platforms. 2016-12-30 23:42:10 -08:00
Mark Adler ee7d7b5dda Add deflateGetDictionary() function.
Per request, but its utility is likely to be very limited. See the
comments in zlib.h.
2016-12-30 16:29:56 -08:00
Mark Adler 9dc5a8585f Speed up deflation for level 0 (storing).
The previous code slid the window and the hash table and copied
every input byte three times in order to just write the data as
stored blocks with no compression. This commit minimizes sliding
and copying, especially for large input and output buffers.

Level 0 compression is now more than 20 times faster than before
the commit.

Most of the speedup is due to deferring hash table slides until
deflateParams() is called to change the compression level away
from 0. More speedup is due to copying directly from next_in to
next_out when the amounts of available input data and output space
permit it, avoiding the intermediate pending buffer. Additionally,
only the last 32K of the used input data is copied back to the
sliding window when large input buffers are provided.
2016-12-04 07:48:47 -08:00
Mark Adler 7161ad76e2 Assure that deflateParams() will not switch functions mid-block.
This alters the specification in zlib.h, so that deflateParams()
will not change any parameters if there is not enough output space
in the event that a block is emitted in order to allow switching
the compression function.
2016-12-04 07:48:47 -08:00
Mark Adler 9674807c82 Fix bugs in creating a very large gzip header. 2016-12-04 07:39:37 -08:00
Mark Adler 03614c56ad Fix some typos. 2016-10-30 08:49:01 -07:00
Mark Adler 94575859cf Fix bug when level 0 used with Z_HUFFMAN or Z_RLE.
Compression level 0 requests no compression, using only stored
blocks. When Z_HUFFMAN or Z_RLE was used with level 0 (granted,
an odd choice, but permitted), the resulting blocks were mostly
fixed or dynamic. The reason is that deflate_stored() was not
being called in that case. The compressed data was valid, but it
was not what the application requested. This commit assures that
only stored blocks are emitted for compression level 0, regardless
of the strategy selected.
2016-10-27 22:50:43 -07:00