Since each element in s->d_buf is 2 bytes, the sx index should be
multiplied by 2 in the assert.
Fixesmadler/zlib#897
madler/zlib#ee474ff2d11715485a87b123edbdd615ba218b88
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%.
madler/zlib#ac8f12c97d1afd9bafa9c710f827d40a407d3266
https://github.com/powturbo/TurboBench links zlib and zlib-ng into the
same binary, causing non-static symbol conflicts. Fix by using PREFIX()
for flush_pending(), bi_reverse(), inflate_ensure_window() and all of
the IBM Z symbols.
Note: do not use an explicit zng_, since one of the long-term goals is
to be able to link two versions of zlib-ng into the same binary for
benchmarking [1].
[1] https://github.com/zlib-ng/zlib-ng/pull/1248#issuecomment-1096648932
When there are no symbols in the tree we skip build_tree calculations and emit a block using static tree with no codes.
trees.c:357:19: runtime error: unsigned integer overflow: 0 - 1 cannot be represented in type 'unsigned long'
#0 0x1000ed79b in build_tree trees.c:357
#1 0x1000ea3f5 in zng_tr_flush_block trees.c:649
#2 0x100090ab0 in deflate_slow deflate_slow.c:131
#3 0x1000572bc in zng_deflate deflate.c:990
#4 0x1000aecd3 in gz_comp gzwrite.c:125
#5 0x1000b05df in zng_gzclose_w gzwrite.c:511
#6 0x1000967a4 in zng_gzclose gzlib.c:253
#7 0x100004f70 in test_gzio example.c:133
#8 0x100010c5b in main example.c:1034
#9 0x7fff71f57cc8 in start+0x0 (libdyld.dylib:x86_64+0x1acc8)
Changed to use uint16_t for all counting variable types.
trees.c(431,45): warning C4244: '+=': conversion from 'int' to 'uint16_t', possible loss of data
trees.c(431,45): warning C4244: '+=': conversion from 'int' to 'uint16_t', possible loss of data
Renamed putShortMSB to put_short_msb and moved to deflate.h with the rest of the put functions.
Added put_uint32 and put_uint32_msb and replaced instances of put_byte with put_short or put_uint32.
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.
make check used to fail with:
trees.c:482:53: runtime error: unsigned integer overflow: 6 - 7 cannot be represented in type 'unsigned int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior trees.c:482:53 in
Patch from Mika Lindqvist.
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.
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.