Commit Graph

106 Commits

Author SHA1 Message Date
Hans Kristian Rosbach
3ac71d9e2f Avoid empty function by renaming bi_flush to zng_tr_flush_bits. 2024-02-12 14:37:19 +01:00
Hans Kristian Rosbach
6f5bdddad1 Remove branch that is almost impossible to hit in bi_flush().
Add case that handles sizes >=48.
2024-02-12 14:37:19 +01:00
Mark Adler
4fe59efbe0 zlib 1.3.1
madler/zlib#51b7f2abdade71cd9bb0e7a373ef2610ec6f9daf
2024-02-07 19:15:56 +01:00
Hans Wennborg
101589d350 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 madler/zlib#897

madler/zlib#ee474ff2d11715485a87b123edbdd615ba218b88
2024-02-07 19:15:56 +01:00
Mark Adler
a3fb271c6e 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%.

madler/zlib#ac8f12c97d1afd9bafa9c710f827d40a407d3266
2024-02-07 19:15:56 +01:00
Mark Adler
5393c21955 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.
2023-02-03 15:49:02 +01:00
Nathan Moinvaziri
d43822b9a7 zlib 1.2.12 2022-06-13 15:58:03 +02:00
Ilya Leoshkevich
9be98893aa Use PREFIX() for some of the Z_INTERNAL symbols
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
2022-04-27 10:37:43 +02:00
Nathan Moinvaziri
0af8678307 Fixed undefined behavior of isgraph when character is not in the range 0 through 0xFF inclusive. 2021-09-03 11:21:09 +02:00
Nathan Moinvaziri
1118fa8ecc Change bi_reverse to use a bit-twiddling hack for 240x speed improvement. 2021-06-13 11:38:09 +02:00
Nathan Moinvaziri
f1f775d1c3 Fixed ubsan error when building tree with no symbols. #782
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)
2020-11-02 18:14:34 +01:00
Nathan Moinvaziri
5cdd9bcdc4 Fixed format specifier warning in build_tree call to Tracev.
Format specifies type 'unsigned long' but the argument has type 'uint32_t' (aka 'unsigned int')
2020-11-02 16:41:05 +01:00
Hans Kristian Rosbach
c3ae9634af Remove FORCE_STATIC and FORCE_STORED 2020-09-11 12:30:36 +02:00
Hans Kristian Rosbach
de160d6585 Minor comments/whitespace cleanup 2020-08-31 13:22:54 +02:00
Nathan Moinvaziri
7cffba4dd6 Rename ZLIB_INTERNAL to Z_INTERNAL for consistency. 2020-08-31 12:33:16 +02:00
Nathan Moinvaziri
b5a81501f2 Rename ZLIB_REGISTER to Z_REGISTER for consistency. 2020-08-31 12:33:16 +02:00
Hans Kristian Rosbach
6264b5a58d Fix more conversion warnings related to s->bi_valid, stored_len and misc. 2020-08-27 19:20:38 +02:00
Nathan Moinvaziri
899f0720ec Renamed trees_p.h to trees.h. 2020-08-27 19:19:30 +02:00
Nathan Moinvaziri
4490d52d0a Rename table headers with tbl suffix. 2020-08-27 19:19:30 +02:00
Nathan Moinvaziri
e1dbcc186a Added ZLIB_REGISTER to disable register keyword for C++.
Co-authored-by: pps83 <pps83@users.noreply.github.com>
2020-06-28 23:01:17 +02:00
Nathan Moinvaziri
8095fa71f0 Fixed whitespace formatting in bi_flush. 2020-06-08 21:16:31 +02:00
Nathan Moinvaziri
75da91b7ed Fixed casting warnings in trees.c with count being int and freq being uint16_t.
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
2020-05-30 21:25:18 +02:00
Nathan Moinvaziri
78a9f84fd6 Fixed warning about bi_flush being defined but not used. #592
trees_emit.h:75:13: warning: ‘bi_flush’ defined but not used
2020-05-30 21:25:18 +02:00
Nathan Moinvaziri
6fb4e882a6 Fixed zero length stored block left open when using Z_SYNC_FLUSH. Moved toggling of block_open back to deflate_quick since zero length stored block doesn't emit end of block code. 2020-05-25 16:40:56 +02:00
Nathan Moinvaziri
600dcc3012 Use 64-bit bit buffer when emitting codes. 2020-05-24 14:06:57 +02:00
Nathan Moinvaziri
e3c858c2c7 Split tree emitting code into its own source header to be included by both trees.c and deflate_quick.c so that their functions can be statically linked for performance reasons. 2020-05-06 09:39:52 +02:00
Nathan Moinvaziri
951764a168 Unify emitting of literals and match dist/lengths. Removed deflate quick static tables, allowing for 32k window. 2020-05-06 09:39:52 +02:00
Pavel P
762068fdc6 Remove cvs keywords 2020-03-17 15:26:47 +01:00
Nathan Moinvaziri
c459b4f5e1 Clean up zng_tr_tally code. 2020-03-13 13:04:37 +01:00
Nathan Moinvaziri
a4d947e85b Renamed bit buffer local variables consistently. 2020-02-08 13:53:43 +01:00
Nathan Moinvaziri
dc0f187636 Change deflate_state's bi_buf from 16-bit to 32-bit. 2020-02-08 13:53:43 +01:00
Nathan Moinvaziri
d06d965ff0 Added better aligned access support for put_short.
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.
2020-02-07 18:36:08 +01:00
Nathan Moinvaziri
e0a711cdde Fixed formatting, 4 spaces for code intent, 2 spaces for preprocessor indent, initial function brace on the same line as definition, removed extraneous spaces and new lines. 2020-02-07 10:44:20 +01:00
Hans Kristian Rosbach
edbfb28397 Use temp variables in send_all_trees too
Re-introduce private temp variables for val and len in send_bits macro.
2019-10-22 09:17:22 +02:00
Hans Kristian Rosbach
bcb7a0b588 Reduce indirections used by send_bits and send_code.
Also simplify the debug tracing into the define instead
of using a separate static function.
x86_64 shows a small performance improvement.
2019-10-22 09:17:22 +02:00
Hans Kristian Rosbach
aaa3cc2f0b Split maketrees out into a separate tool 2019-09-20 22:29:21 +02:00
Nathan Moinvaziri
f06c71f981 Add zng_ prefix to internal functions to avoid linking conflicts with zlib. (#363) 2019-07-18 13:21:13 +02:00
Ilya Leoshkevich
b7f659f2fa Introduce inflate_ensure_window, make bi_reverse and flush_pending ZLIB_INTERNAL 2019-05-23 12:44:59 +02:00
Mark Adler
eea0214008 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.
2019-03-27 13:00:25 +01:00
Mark Adler
a9f5d668f6 Make the names in functions declarations identical to definitions. 2018-12-13 14:28:50 +01:00
Sebastian Pop
e9a016858a fix bug #210: split statement in two to avoid substract overflow
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.
2018-12-12 17:21:40 +01:00
Mark Adler
ccbb3fef5a 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-11-14 09:21:26 +01:00
Mika Lindqvist
df1fd1567f Move private defines from zconf.h and zconf-ng.h to zbuild.h
* move definition of z_size_t to zbuild.h
2018-03-22 10:18:27 +01:00
Mark Adler
17a4df5a5e
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-13 11:03:16 +03:00
Milan Ševčík
c295c64091 Make code an int in compress_block()
send_code() expects int instead of unsigned. Other procedures do pass
int.
2017-08-17 11:59:27 +02:00
Mark Adler
01c23ef53a Update vestigial comment from very old Info-ZIP deflate. 2017-02-13 10:08:35 +01:00
Mark Adler
2a51c84f6c zlib 1.2.9 2017-02-09 11:39:40 +01:00
Mark Adler
a7edd5a1a6 Avoid some random compiler warnings on various platforms. 2017-02-07 10:33:09 +01:00
Mark Adler
23b4bb3ec4 Avoid use of DEBUG macro -- change to ZLIB_DEBUG. 2017-02-06 14:33:22 +01:00
Mark Adler
fe196b9a50 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.
2017-02-01 13:48:42 +01:00