Commit Graph

58 Commits

Author SHA1 Message Date
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
Levi Broderick 8a76f02e0e Avoid implicit conversion warnings in deflate.c and trees.c. 2024-01-23 08:45:00 -08:00
Mark Adler 51b7f2abda zlib 1.3.1 2024-01-22 10:32:37 -08:00
Hans Wennborg ee474ff2d1 Fix pending buffer overflow assert with LIT_MEM allocation.
Since each element in s->d_buf is 2 bytes, the sx index should be
multiplied by 2 in the assert.

Fixes #897
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 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 84c6716a48 Minor formatting improvements.
No code changes.
2022-10-05 15:17:52 -07:00
Mark Adler 7fabcb5357 Fix bug in block type selection when Z_FIXED used.
A fixed block could be chosen when a stored block was smaller. Now
the smaller of the two is always chosen.
2022-10-03 11:42:18 -07:00
Mark Adler 5752b171fd Fix some typos.
No code changes.
2022-08-23 15:35:13 -07:00
Mark Adler 3df842426b Silence some warnings from Visual Studio C. 2022-03-28 10:50:16 -07:00
Mark Adler 21767c654d zlib 1.2.12 2022-03-27 16:05:02 -07:00
Mark Adler 8678871f18 Replace black/white with allow/block. (theresa-m) 2021-12-31 16:57:07 -08: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 a577351394 Make the names in functions declarations identical to definitions. 2017-10-12 20:03:51 -07:00
Mark Adler 723e928b84 Avoid an undefined behavior of memcpy() in _tr_stored_block().
Allegedly the behavior of memcpy() is undefined if the source
pointer is NULL, even if the number of bytes to copy is zero.
2017-10-12 19:44:01 -07:00
Mark Adler 37ed2112a1 Update vestigial comment from very old Info-ZIP deflate. 2017-01-15 09:07:14 -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 21c66cd5ac Increase verbosity required to warn about bit length overflow.
When debugging the Huffman coding would warn about resulting codes
greater than 15 bits in length. This is handled properly, and is
not uncommon. This increases the verbosity of the warning by one,
so that it is not displayed by default.
2016-12-04 07:48:47 -08:00
Mark Adler a456d898bb Use memcpy for stored blocks.
This speeds up level 0 by about a factor of three, as compared to
the previous byte-at-a-time loop. We can do much better though. A
later commit avoids this copy for level 0 with large buffers,
instead copying directly from the input to the output. This commit
still speeds up storing incompressible data found when compressing
normally.
2016-12-04 07:39:25 -08:00
Mark Adler 7096424f23 Clean up type conversions. 2016-10-11 22:15:50 -07:00
Mark Adler 82e9dc6093 Use const for static tree descriptions in deflate.
This is in order to permit shared memory for these structures.
2015-08-15 18:04:50 -07:00
Mark Adler 51a223def4 Avoid use of DEBUG macro -- change to ZLIB_DEBUG. 2015-07-28 22:44:31 -07:00
Mark Adler 62d6112a79 Clean up the usage of z_const and respect const usage within zlib.
This patch allows zlib to compile cleanly with the -Wcast-qual gcc
warning enabled, but only if ZLIB_CONST is defined, which adds
const to next_in and msg in z_stream and in the in_func prototype.
A --const option is added to ./configure which adds -DZLIB_CONST
to the compile flags, and adds -Wcast-qual to the compile flags
when ZLIBGCCWARN is set in the environment.
2012-08-13 00:02:40 -07:00
Mark Adler 0b828b4aa6 Write out all of the available bits when using Z_BLOCK.
Previously, the bit buffer would hold 1 to 16 bits after "all" of the
output is provided after a Z_BLOCK deflate() call.  Now at most seven
bits remain in the output buffer after Z_BLOCK.  flush_pending() now
flushes the bit buffer before copying out the byte buffer, in order
for it to really flush as much as possible.
2012-01-07 14:08:02 -08:00
Mark Adler 8f5eceefe8 Remove second empty static block for Z_PARTIAL_FLUSH.
Z_PARTIAL_FLUSH would sometimes emit two empty static blocks instead
of one in order to provide enough lookahead for inflate to be able
to decode what was last compressed.  inflate no longer needs that
much lookahead, so this removes the possibility of emitting the
second empty static block.  Z_PARTIAL_FLUSH will now emit only one
empty static block.
2012-01-07 14:03:07 -08:00
Mark Adler 263b1a05b0 Allow deflatePrime() to insert bits in the middle of a stream.
This allows the insertion of multiple empty static blocks for the
purpose of efficiently bringing a stream to a byte boundary.
2012-01-07 14:03:07 -08:00
Mark Adler 9712272c78 zlib 1.2.5 2011-09-09 23:35:10 -07:00
Mark Adler 7301420248 zlib 1.2.4.5 2011-09-09 23:34:55 -07:00
Mark Adler 67cc20d004 zlib 1.2.4-pre1 2011-09-09 23:32:36 -07:00
Mark Adler f6194ef39a zlib 1.2.3.4 2011-09-09 23:26:40 -07:00
Mark Adler b1c19ca6d8 zlib 1.2.3.1 2011-09-09 23:25:27 -07:00
Mark Adler 9c3a583021 zlib 1.2.2.4 2011-09-09 23:24:52 -07:00
Mark Adler 0484693e17 zlib 1.2.2.2 2011-09-09 23:24:33 -07:00
Mark Adler 9811b53dd9 zlib 1.2.2.1 2011-09-09 23:24:24 -07:00
Mark Adler 7a6955760b zlib 1.2.1.2 2011-09-09 23:23:45 -07:00
Mark Adler b97ec631c6 zlib 1.2.0.7 2011-09-09 23:23:01 -07:00
Mark Adler 13a294f044 zlib 1.2.0.1 2011-09-09 23:21:57 -07:00
Mark Adler 7c2a874e50 zlib 1.2.0 2011-09-09 23:21:47 -07:00
Mark Adler a383133c4e zlib 1.1.4 2011-09-09 23:20:42 -07:00
Mark Adler 14763ac7c6 zlib 1.1.3 2011-09-09 23:20:29 -07:00
Mark Adler 02b6cf579f zlib 1.1.1 2011-09-09 23:20:07 -07:00
Mark Adler 965fe72aed zlib 1.1.0 2011-09-09 23:19:55 -07:00
Mark Adler 6759211ad8 zlib 1.0.8 2011-09-09 23:18:57 -07:00
Mark Adler 7850e4e406 zlib 1.0.7 2011-09-09 23:17:33 -07:00
Mark Adler ff11b0a61f zlib 1.0.4 2011-09-09 23:17:02 -07:00
Mark Adler e26a448e96 zlib 1.0.2 2011-09-09 23:15:17 -07:00
Mark Adler 423eb40306 zlib 1.0.1 2011-09-09 23:14:39 -07:00
Mark Adler 8a2acbffc8 zlib 1.0-pre 2011-09-09 23:13:27 -07:00
Mark Adler 56bcb184fa zlib 0.99 2011-09-09 23:11:37 -07:00