- updated zlib to 1.2.12

https://www.zlib.net/zlib-1.2.12.tar.gz
This commit is contained in:
alexey.lysiuk 2022-03-31 09:47:31 +03:00
parent eeb67bcec3
commit 4049a0d8f1
18 changed files with 10865 additions and 1033 deletions

View file

@ -1,6 +1,69 @@
ChangeLog file for zlib ChangeLog file for zlib
Changes in 1.2.12 (27 Mar 2022)
- Cygwin does not have _wopen(), so do not create gzopen_w() there
- Permit a deflateParams() parameter change as soon as possible
- Limit hash table inserts after switch from stored deflate
- Fix bug when window full in deflate_stored()
- Fix CLEAR_HASH macro to be usable as a single statement
- Avoid a conversion error in gzseek when off_t type too small
- Have Makefile return non-zero error code on test failure
- Avoid some conversion warnings in gzread.c and gzwrite.c
- Update use of errno for newer Windows CE versions
- Small speedup to inflate [psumbera]
- Return an error if the gzputs string length can't fit in an int
- Add address checking in clang to -w option of configure
- Don't compute check value for raw inflate if asked to validate
- Handle case where inflateSync used when header never processed
- Avoid the use of ptrdiff_t
- Avoid an undefined behavior of memcpy() in gzappend()
- Avoid undefined behaviors of memcpy() in gz*printf()
- Avoid an undefined behavior of memcpy() in _tr_stored_block()
- Make the names in functions declarations identical to definitions
- Remove old assembler code in which bugs have manifested
- Fix deflateEnd() to not report an error at start of raw deflate
- Add legal disclaimer to README
- Emphasize the need to continue decompressing gzip members
- Correct the initialization requirements for deflateInit2()
- Fix a bug that can crash deflate on some input when using Z_FIXED
- Assure that the number of bits for deflatePrime() is valid
- Use a structure to make globals in enough.c evident
- Use a macro for the printf format of big_t in enough.c
- Clean up code style in enough.c, update version
- Use inline function instead of macro for index in enough.c
- Clarify that prefix codes are counted in enough.c
- Show all the codes for the maximum tables size in enough.c
- Add gznorm.c example, which normalizes gzip files
- Fix the zran.c example to work on a multiple-member gzip file
- Add tables for crc32_combine(), to speed it up by a factor of 200
- Add crc32_combine_gen() and crc32_combine_op() for fast combines
- Speed up software CRC-32 computation by a factor of 1.5 to 3
- Use atomic test and set, if available, for dynamic CRC tables
- Don't bother computing check value after successful inflateSync()
- Correct comment in crc32.c
- Add use of the ARMv8 crc32 instructions when requested
- Use ARM crc32 instructions if the ARM architecture has them
- Explicitly note that the 32-bit check values are 32 bits
- Avoid adding empty gzip member after gzflush with Z_FINISH
- Fix memory leak on error in gzlog.c
- Fix error in comment on the polynomial representation of a byte
- Clarify gz* function interfaces, referring to parameter names
- Change macro name in inflate.c to avoid collision in VxWorks
- Correct typo in blast.c
- Improve portability of contrib/minizip
- Fix indentation in minizip's zip.c
- Replace black/white with allow/block. (theresa-m)
- minizip warning fix if MAXU32 already defined. (gvollant)
- Fix unztell64() in minizip to work past 4GB. (Daniël Hörchner)
- Clean up minizip to reduce warnings for testing
- Add fallthrough comments for gcc
- Eliminate use of ULL constants
- Separate out address sanitizing from warnings in configure
- Remove destructive aspects of make distclean
- Check for cc masquerading as gcc or clang in configure
- Fix crc32.c to compile local functions only if used
Changes in 1.2.11 (15 Jan 2017) Changes in 1.2.11 (15 Jan 2017)
- Fix deflate stored bug when pulling last block from window - Fix deflate stored bug when pulling last block from window
- Permit immediate deflateParams changes before any deflate input - Permit immediate deflateParams changes before any deflate input
@ -511,7 +574,7 @@ Changes in 1.2.3.5 (8 Jan 2010)
- Don't use _vsnprintf on later versions of MSVC [Lowman] - Don't use _vsnprintf on later versions of MSVC [Lowman]
- Add CMake build script and input file [Lowman] - Add CMake build script and input file [Lowman]
- Update contrib/minizip to 1.1 [Svensson, Vollant] - Update contrib/minizip to 1.1 [Svensson, Vollant]
- Moved nintendods directory from contrib to . - Moved nintendods directory from contrib to root
- Replace gzio.c with a new set of routines with the same functionality - Replace gzio.c with a new set of routines with the same functionality
- Add gzbuffer(), gzoffset(), gzclose_r(), gzclose_w() as part of above - Add gzbuffer(), gzoffset(), gzclose_r(), gzclose_w() as part of above
- Update contrib/minizip to 1.1b - Update contrib/minizip to 1.1b
@ -685,7 +748,7 @@ Changes in 1.2.2.4 (11 July 2005)
- Be more strict on incomplete code sets in inflate_table() and increase - Be more strict on incomplete code sets in inflate_table() and increase
ENOUGH and MAXD -- this repairs a possible security vulnerability for ENOUGH and MAXD -- this repairs a possible security vulnerability for
invalid inflate input. Thanks to Tavis Ormandy and Markus Oberhumer for invalid inflate input. Thanks to Tavis Ormandy and Markus Oberhumer for
discovering the vulnerability and providing test cases. discovering the vulnerability and providing test cases
- Add ia64 support to configure for HP-UX [Smith] - Add ia64 support to configure for HP-UX [Smith]
- Add error return to gzread() for format or i/o error [Levin] - Add error return to gzread() for format or i/o error [Levin]
- Use malloc.h for OS/2 [Necasek] - Use malloc.h for OS/2 [Necasek]
@ -721,7 +784,7 @@ Changes in 1.2.2.2 (30 December 2004)
- Add Z_FIXED strategy option to deflateInit2() to force fixed trees - Add Z_FIXED strategy option to deflateInit2() to force fixed trees
- Add updated make_vms.com [Coghlan], update README - Add updated make_vms.com [Coghlan], update README
- Create a new "examples" directory, move gzappend.c there, add zpipe.c, - Create a new "examples" directory, move gzappend.c there, add zpipe.c,
fitblk.c, gzlog.[ch], gzjoin.c, and zlib_how.html. fitblk.c, gzlog.[ch], gzjoin.c, and zlib_how.html
- Add FAQ entry and comments in deflate.c on uninitialized memory access - Add FAQ entry and comments in deflate.c on uninitialized memory access
- Add Solaris 9 make options in configure [Gilbert] - Add Solaris 9 make options in configure [Gilbert]
- Allow strerror() usage in gzio.c for STDC - Allow strerror() usage in gzio.c for STDC
@ -792,7 +855,7 @@ Changes in 1.2.1.1 (9 January 2004)
- Fix a big fat bug in inftrees.c that prevented decoding valid - Fix a big fat bug in inftrees.c that prevented decoding valid
dynamic blocks with only literals and no distance codes -- dynamic blocks with only literals and no distance codes --
Thanks to "Hot Emu" for the bug report and sample file Thanks to "Hot Emu" for the bug report and sample file
- Add a note to puff.c on no distance codes case. - Add a note to puff.c on no distance codes case
Changes in 1.2.1 (17 November 2003) Changes in 1.2.1 (17 November 2003)
- Remove a tab in contrib/gzappend/gzappend.c - Remove a tab in contrib/gzappend/gzappend.c
@ -1036,14 +1099,14 @@ Changes in 1.2.0 (9 March 2003)
- Add contrib/puff/ simple inflate for deflate format description - Add contrib/puff/ simple inflate for deflate format description
Changes in 1.1.4 (11 March 2002) Changes in 1.1.4 (11 March 2002)
- ZFREE was repeated on same allocation on some error conditions. - ZFREE was repeated on same allocation on some error conditions
This creates a security problem described in This creates a security problem described in
http://www.zlib.org/advisory-2002-03-11.txt http://www.zlib.org/advisory-2002-03-11.txt
- Returned incorrect error (Z_MEM_ERROR) on some invalid data - Returned incorrect error (Z_MEM_ERROR) on some invalid data
- Avoid accesses before window for invalid distances with inflate window - Avoid accesses before window for invalid distances with inflate window
less than 32K. less than 32K
- force windowBits > 8 to avoid a bug in the encoder for a window size - force windowBits > 8 to avoid a bug in the encoder for a window size
of 256 bytes. (A complete fix will be available in 1.1.5). of 256 bytes. (A complete fix will be available in 1.1.5)
Changes in 1.1.3 (9 July 1998) Changes in 1.1.3 (9 July 1998)
- fix "an inflate input buffer bug that shows up on rare but persistent - fix "an inflate input buffer bug that shows up on rare but persistent
@ -1117,7 +1180,7 @@ Changes in 1.1.1 (27 Feb 98)
- remove block truncation heuristic which had very marginal effect for zlib - remove block truncation heuristic which had very marginal effect for zlib
(smaller lit_bufsize than in gzip 1.2.4) and degraded a little the (smaller lit_bufsize than in gzip 1.2.4) and degraded a little the
compression ratio on some files. This also allows inlining _tr_tally for compression ratio on some files. This also allows inlining _tr_tally for
matches in deflate_slow. matches in deflate_slow
- added msdos/Makefile.w32 for WIN32 Microsoft Visual C++ (Bob Frazier) - added msdos/Makefile.w32 for WIN32 Microsoft Visual C++ (Bob Frazier)
Changes in 1.1.0 (24 Feb 98) Changes in 1.1.0 (24 Feb 98)
@ -1162,7 +1225,7 @@ Changes in 1.0.8 (27 Jan 1998)
- include sys/types.h to get off_t on some systems (Marc Lehmann & QingLong) - include sys/types.h to get off_t on some systems (Marc Lehmann & QingLong)
- use constant arrays for the static trees in trees.c instead of computing - use constant arrays for the static trees in trees.c instead of computing
them at run time (thanks to Ken Raeburn for this suggestion). To create them at run time (thanks to Ken Raeburn for this suggestion). To create
trees.h, compile with GEN_TREES_H and run "make test". trees.h, compile with GEN_TREES_H and run "make test"
- check return code of example in "make test" and display result - check return code of example in "make test" and display result
- pass minigzip command line options to file_compress - pass minigzip command line options to file_compress
- simplifying code of inflateSync to avoid gcc 2.8 bug - simplifying code of inflateSync to avoid gcc 2.8 bug
@ -1201,12 +1264,12 @@ Changes in 1.0.6 (19 Jan 1998)
- add functions gzprintf, gzputc, gzgetc, gztell, gzeof, gzseek, gzrewind and - add functions gzprintf, gzputc, gzgetc, gztell, gzeof, gzseek, gzrewind and
gzsetparams (thanks to Roland Giersig and Kevin Ruland for some of this code) gzsetparams (thanks to Roland Giersig and Kevin Ruland for some of this code)
- Fix a deflate bug occurring only with compression level 0 (thanks to - Fix a deflate bug occurring only with compression level 0 (thanks to
Andy Buckler for finding this one). Andy Buckler for finding this one)
- In minigzip, pass transparently also the first byte for .Z files. - In minigzip, pass transparently also the first byte for .Z files
- return Z_BUF_ERROR instead of Z_OK if output buffer full in uncompress() - return Z_BUF_ERROR instead of Z_OK if output buffer full in uncompress()
- check Z_FINISH in inflate (thanks to Marc Schluper) - check Z_FINISH in inflate (thanks to Marc Schluper)
- Implement deflateCopy (thanks to Adam Costello) - Implement deflateCopy (thanks to Adam Costello)
- make static libraries by default in configure, add --shared option. - make static libraries by default in configure, add --shared option
- move MSDOS or Windows specific files to directory msdos - move MSDOS or Windows specific files to directory msdos
- suppress the notion of partial flush to simplify the interface - suppress the notion of partial flush to simplify the interface
(but the symbol Z_PARTIAL_FLUSH is kept for compatibility with 1.0.4) (but the symbol Z_PARTIAL_FLUSH is kept for compatibility with 1.0.4)
@ -1218,7 +1281,7 @@ Changes in 1.0.6 (19 Jan 1998)
- added Makefile.nt (thanks to Stephen Williams) - added Makefile.nt (thanks to Stephen Williams)
- added the unsupported "contrib" directory: - added the unsupported "contrib" directory:
contrib/asm386/ by Gilles Vollant <info@winimage.com> contrib/asm386/ by Gilles Vollant <info@winimage.com>
386 asm code replacing longest_match(). 386 asm code replacing longest_match()
contrib/iostream/ by Kevin Ruland <kevin@rodin.wustl.edu> contrib/iostream/ by Kevin Ruland <kevin@rodin.wustl.edu>
A C++ I/O streams interface to the zlib gz* functions A C++ I/O streams interface to the zlib gz* functions
contrib/iostream2/ by Tyge Løvset <Tyge.Lovset@cmr.no> contrib/iostream2/ by Tyge Løvset <Tyge.Lovset@cmr.no>
@ -1226,7 +1289,7 @@ Changes in 1.0.6 (19 Jan 1998)
contrib/untgz/ by "Pedro A. Aranda Guti\irrez" <paag@tid.es> contrib/untgz/ by "Pedro A. Aranda Guti\irrez" <paag@tid.es>
A very simple tar.gz file extractor using zlib A very simple tar.gz file extractor using zlib
contrib/visual-basic.txt by Carlos Rios <c_rios@sonda.cl> contrib/visual-basic.txt by Carlos Rios <c_rios@sonda.cl>
How to use compress(), uncompress() and the gz* functions from VB. How to use compress(), uncompress() and the gz* functions from VB
- pass params -f (filtered data), -h (huffman only), -1 to -9 (compression - pass params -f (filtered data), -h (huffman only), -1 to -9 (compression
level) in minigzip (thanks to Tom Lane) level) in minigzip (thanks to Tom Lane)
@ -1235,8 +1298,8 @@ Changes in 1.0.6 (19 Jan 1998)
- add undocumented function inflateSyncPoint() (hack for Paul Mackerras) - add undocumented function inflateSyncPoint() (hack for Paul Mackerras)
- add undocumented function zError to convert error code to string - add undocumented function zError to convert error code to string
(for Tim Smithers) (for Tim Smithers)
- Allow compilation of gzio with -DNO_DEFLATE to avoid the compression code. - Allow compilation of gzio with -DNO_DEFLATE to avoid the compression code
- Use default memcpy for Symantec MSDOS compiler. - Use default memcpy for Symantec MSDOS compiler
- Add EXPORT keyword for check_func (needed for Windows DLL) - Add EXPORT keyword for check_func (needed for Windows DLL)
- add current directory to LD_LIBRARY_PATH for "make test" - add current directory to LD_LIBRARY_PATH for "make test"
- create also a link for libz.so.1 - create also a link for libz.so.1
@ -1249,7 +1312,7 @@ Changes in 1.0.6 (19 Jan 1998)
- allow compilation with ANSI keywords only enabled for TurboC in large model - allow compilation with ANSI keywords only enabled for TurboC in large model
- avoid "versionString"[0] (Borland bug) - avoid "versionString"[0] (Borland bug)
- add NEED_DUMMY_RETURN for Borland - add NEED_DUMMY_RETURN for Borland
- use variable z_verbose for tracing in debug mode (L. Peter Deutsch). - use variable z_verbose for tracing in debug mode (L. Peter Deutsch)
- allow compilation with CC - allow compilation with CC
- defined STDC for OS/2 (David Charlap) - defined STDC for OS/2 (David Charlap)
- limit external names to 8 chars for MVS (Thomas Lund) - limit external names to 8 chars for MVS (Thomas Lund)
@ -1259,7 +1322,7 @@ Changes in 1.0.6 (19 Jan 1998)
- use _fdopen instead of fdopen for MSC >= 6.0 (Thomas Fanslau) - use _fdopen instead of fdopen for MSC >= 6.0 (Thomas Fanslau)
- added makelcc.bat for lcc-win32 (Tom St Denis) - added makelcc.bat for lcc-win32 (Tom St Denis)
- in Makefile.dj2, use copy and del instead of install and rm (Frank Donahoe) - in Makefile.dj2, use copy and del instead of install and rm (Frank Donahoe)
- Avoid expanded $Id$. Use "rcs -kb" or "cvs admin -kb" to avoid Id expansion. - Avoid expanded $Id$. Use "rcs -kb" or "cvs admin -kb" to avoid Id expansion
- check for unistd.h in configure (for off_t) - check for unistd.h in configure (for off_t)
- remove useless check parameter in inflate_blocks_free - remove useless check parameter in inflate_blocks_free
- avoid useless assignment of s->check to itself in inflate_blocks_new - avoid useless assignment of s->check to itself in inflate_blocks_new
@ -1280,7 +1343,7 @@ Changes in 1.0.5 (3 Jan 98)
Changes in 1.0.4 (24 Jul 96) Changes in 1.0.4 (24 Jul 96)
- In very rare conditions, deflate(s, Z_FINISH) could fail to produce an EOF - In very rare conditions, deflate(s, Z_FINISH) could fail to produce an EOF
bit, so the decompressor could decompress all the correct data but went bit, so the decompressor could decompress all the correct data but went
on to attempt decompressing extra garbage data. This affected minigzip too. on to attempt decompressing extra garbage data. This affected minigzip too
- zlibVersion and gzerror return const char* (needed for DLL) - zlibVersion and gzerror return const char* (needed for DLL)
- port to RISCOS (no fdopen, no multiple dots, no unlink, no fileno) - port to RISCOS (no fdopen, no multiple dots, no unlink, no fileno)
- use z_error only for DEBUG (avoid problem with DLLs) - use z_error only for DEBUG (avoid problem with DLLs)
@ -1310,7 +1373,7 @@ Changes in 1.0.1 (20 May 96) [1.0 skipped to avoid confusion]
- fix array overlay in deflate.c which sometimes caused bad compressed data - fix array overlay in deflate.c which sometimes caused bad compressed data
- fix inflate bug with empty stored block - fix inflate bug with empty stored block
- fix MSDOS medium model which was broken in 0.99 - fix MSDOS medium model which was broken in 0.99
- fix deflateParams() which could generate bad compressed data. - fix deflateParams() which could generate bad compressed data
- Bytef is define'd instead of typedef'ed (work around Borland bug) - Bytef is define'd instead of typedef'ed (work around Borland bug)
- added an INDEX file - added an INDEX file
- new makefiles for DJGPP (Makefile.dj2), 32-bit Borland (Makefile.b32), - new makefiles for DJGPP (Makefile.dj2), 32-bit Borland (Makefile.b32),
@ -1331,7 +1394,7 @@ Changes in 0.99 (27 Jan 96)
- allow preset dictionary shared between compressor and decompressor - allow preset dictionary shared between compressor and decompressor
- allow compression level 0 (no compression) - allow compression level 0 (no compression)
- add deflateParams in zlib.h: allow dynamic change of compression level - add deflateParams in zlib.h: allow dynamic change of compression level
and compression strategy. and compression strategy
- test large buffers and deflateParams in example.c - test large buffers and deflateParams in example.c
- add optional "configure" to build zlib as a shared library - add optional "configure" to build zlib as a shared library
- suppress Makefile.qnx, use configure instead - suppress Makefile.qnx, use configure instead
@ -1373,30 +1436,30 @@ Changes in 0.99 (27 Jan 96)
- use STDC instead of __GO32__ to avoid redeclaring exit, calloc, etc... - use STDC instead of __GO32__ to avoid redeclaring exit, calloc, etc...
- use Z_BINARY instead of BINARY - use Z_BINARY instead of BINARY
- document that gzclose after gzdopen will close the file - document that gzclose after gzdopen will close the file
- allow "a" as mode in gzopen. - allow "a" as mode in gzopen
- fix error checking in gzread - fix error checking in gzread
- allow skipping .gz extra-field on pipes - allow skipping .gz extra-field on pipes
- added reference to Perl interface in README - added reference to Perl interface in README
- put the crc table in FAR data (I dislike more and more the medium model :) - put the crc table in FAR data (I dislike more and more the medium model :)
- added get_crc_table - added get_crc_table
- added a dimension to all arrays (Borland C can't count). - added a dimension to all arrays (Borland C can't count)
- workaround Borland C bug in declaration of inflate_codes_new & inflate_fast - workaround Borland C bug in declaration of inflate_codes_new & inflate_fast
- guard against multiple inclusion of *.h (for precompiled header on Mac) - guard against multiple inclusion of *.h (for precompiled header on Mac)
- Watcom C pretends to be Microsoft C small model even in 32 bit mode. - Watcom C pretends to be Microsoft C small model even in 32 bit mode
- don't use unsized arrays to avoid silly warnings by Visual C++: - don't use unsized arrays to avoid silly warnings by Visual C++:
warning C4746: 'inflate_mask' : unsized array treated as '__far' warning C4746: 'inflate_mask' : unsized array treated as '__far'
(what's wrong with far data in far model?). (what's wrong with far data in far model?)
- define enum out of inflate_blocks_state to allow compilation with C++ - define enum out of inflate_blocks_state to allow compilation with C++
Changes in 0.95 (16 Aug 95) Changes in 0.95 (16 Aug 95)
- fix MSDOS small and medium model (now easier to adapt to any compiler) - fix MSDOS small and medium model (now easier to adapt to any compiler)
- inlined send_bits - inlined send_bits
- fix the final (:-) bug for deflate with flush (output was correct but - fix the final (:-) bug for deflate with flush (output was correct but
not completely flushed in rare occasions). not completely flushed in rare occasions)
- default window size is same for compression and decompression - default window size is same for compression and decompression
(it's now sufficient to set MAX_WBITS in zconf.h). (it's now sufficient to set MAX_WBITS in zconf.h)
- voidp -> voidpf and voidnp -> voidp (for consistency with other - voidp -> voidpf and voidnp -> voidp (for consistency with other
typedefs and because voidnp was not near in large model). typedefs and because voidnp was not near in large model)
Changes in 0.94 (13 Aug 95) Changes in 0.94 (13 Aug 95)
- support MSDOS medium model - support MSDOS medium model
@ -1405,12 +1468,12 @@ Changes in 0.94 (13 Aug 95)
- added support for VMS - added support for VMS
- allow a compression level in gzopen() - allow a compression level in gzopen()
- gzflush now calls fflush - gzflush now calls fflush
- For deflate with flush, flush even if no more input is provided. - For deflate with flush, flush even if no more input is provided
- rename libgz.a as libz.a - rename libgz.a as libz.a
- avoid complex expression in infcodes.c triggering Turbo C bug - avoid complex expression in infcodes.c triggering Turbo C bug
- work around a problem with gcc on Alpha (in INSERT_STRING) - work around a problem with gcc on Alpha (in INSERT_STRING)
- don't use inline functions (problem with some gcc versions) - don't use inline functions (problem with some gcc versions)
- allow renaming of Byte, uInt, etc... with #define. - allow renaming of Byte, uInt, etc... with #define
- avoid warning about (unused) pointer before start of array in deflate.c - avoid warning about (unused) pointer before start of array in deflate.c
- avoid various warnings in gzio.c, example.c, infblock.c, adler32.c, zutil.c - avoid various warnings in gzio.c, example.c, infblock.c, adler32.c, zutil.c
- avoid reserved word 'new' in trees.c - avoid reserved word 'new' in trees.c
@ -1429,7 +1492,7 @@ Changes in 0.92 (3 May 95)
- no memcpy on Pyramid - no memcpy on Pyramid
- suppressed inftest.c - suppressed inftest.c
- optimized fill_window, put longest_match inline for gcc - optimized fill_window, put longest_match inline for gcc
- optimized inflate on stored blocks. - optimized inflate on stored blocks
- untabify all sources to simplify patches - untabify all sources to simplify patches
Changes in 0.91 (2 May 95) Changes in 0.91 (2 May 95)
@ -1447,7 +1510,7 @@ Changes in 0.9 (1 May 95)
- let again gzread copy uncompressed data unchanged (was working in 0.71) - let again gzread copy uncompressed data unchanged (was working in 0.71)
- deflate(Z_FULL_FLUSH), inflateReset and inflateSync are now fully implemented - deflate(Z_FULL_FLUSH), inflateReset and inflateSync are now fully implemented
- added a test of inflateSync in example.c - added a test of inflateSync in example.c
- moved MAX_WBITS to zconf.h because users might want to change that. - moved MAX_WBITS to zconf.h because users might want to change that
- document explicitly that zalloc(64K) on MSDOS must return a normalized - document explicitly that zalloc(64K) on MSDOS must return a normalized
pointer (zero offset) pointer (zero offset)
- added Makefiles for Microsoft C, Turbo C, Borland C++ - added Makefiles for Microsoft C, Turbo C, Borland C++
@ -1456,7 +1519,7 @@ Changes in 0.9 (1 May 95)
Changes in 0.8 (29 April 95) Changes in 0.8 (29 April 95)
- added fast inflate (inffast.c) - added fast inflate (inffast.c)
- deflate(Z_FINISH) now returns Z_STREAM_END when done. Warning: this - deflate(Z_FINISH) now returns Z_STREAM_END when done. Warning: this
is incompatible with previous versions of zlib which returned Z_OK. is incompatible with previous versions of zlib which returned Z_OK
- work around a TurboC compiler bug (bad code for b << 0, see infutil.h) - work around a TurboC compiler bug (bad code for b << 0, see infutil.h)
(actually that was not a compiler bug, see 0.81 above) (actually that was not a compiler bug, see 0.81 above)
- gzread no longer reads one extra byte in certain cases - gzread no longer reads one extra byte in certain cases
@ -1466,50 +1529,50 @@ Changes in 0.8 (29 April 95)
Changes in 0.71 (14 April 95) Changes in 0.71 (14 April 95)
- Fixed more MSDOS compilation problems :( There is still a bug with - Fixed more MSDOS compilation problems :( There is still a bug with
TurboC large model. TurboC large model
Changes in 0.7 (14 April 95) Changes in 0.7 (14 April 95)
- Added full inflate support. - Added full inflate support
- Simplified the crc32() interface. The pre- and post-conditioning - Simplified the crc32() interface. The pre- and post-conditioning
(one's complement) is now done inside crc32(). WARNING: this is (one's complement) is now done inside crc32(). WARNING: this is
incompatible with previous versions; see zlib.h for the new usage. incompatible with previous versions; see zlib.h for the new usage
Changes in 0.61 (12 April 95) Changes in 0.61 (12 April 95)
- workaround for a bug in TurboC. example and minigzip now work on MSDOS. - workaround for a bug in TurboC. example and minigzip now work on MSDOS
Changes in 0.6 (11 April 95) Changes in 0.6 (11 April 95)
- added minigzip.c - added minigzip.c
- added gzdopen to reopen a file descriptor as gzFile - added gzdopen to reopen a file descriptor as gzFile
- added transparent reading of non-gziped files in gzread. - added transparent reading of non-gziped files in gzread
- fixed bug in gzread (don't read crc as data) - fixed bug in gzread (don't read crc as data)
- fixed bug in destroy (gzio.c) (don't return Z_STREAM_END for gzclose). - fixed bug in destroy (gzio.c) (don't return Z_STREAM_END for gzclose)
- don't allocate big arrays in the stack (for MSDOS) - don't allocate big arrays in the stack (for MSDOS)
- fix some MSDOS compilation problems - fix some MSDOS compilation problems
Changes in 0.5: Changes in 0.5:
- do real compression in deflate.c. Z_PARTIAL_FLUSH is supported but - do real compression in deflate.c. Z_PARTIAL_FLUSH is supported but
not yet Z_FULL_FLUSH. not yet Z_FULL_FLUSH
- support decompression but only in a single step (forced Z_FINISH) - support decompression but only in a single step (forced Z_FINISH)
- added opaque object for zalloc and zfree. - added opaque object for zalloc and zfree
- added deflateReset and inflateReset - added deflateReset and inflateReset
- added a variable zlib_version for consistency checking. - added a variable zlib_version for consistency checking
- renamed the 'filter' parameter of deflateInit2 as 'strategy'. - renamed the 'filter' parameter of deflateInit2 as 'strategy'
Added Z_FILTERED and Z_HUFFMAN_ONLY constants. Added Z_FILTERED and Z_HUFFMAN_ONLY constants
Changes in 0.4: Changes in 0.4:
- avoid "zip" everywhere, use zlib instead of ziplib. - avoid "zip" everywhere, use zlib instead of ziplib
- suppress Z_BLOCK_FLUSH, interpret Z_PARTIAL_FLUSH as block flush - suppress Z_BLOCK_FLUSH, interpret Z_PARTIAL_FLUSH as block flush
if compression method == 8. if compression method == 8
- added adler32 and crc32 - added adler32 and crc32
- renamed deflateOptions as deflateInit2, call one or the other but not both - renamed deflateOptions as deflateInit2, call one or the other but not both
- added the method parameter for deflateInit2. - added the method parameter for deflateInit2
- added inflateInit2 - added inflateInit2
- simplied considerably deflateInit and inflateInit by not supporting - simplied considerably deflateInit and inflateInit by not supporting
user-provided history buffer. This is supported only in deflateInit2 user-provided history buffer. This is supported only in deflateInit2
and inflateInit2. and inflateInit2
Changes in 0.3: Changes in 0.3:
- prefix all macro names with Z_ - prefix all macro names with Z_
- use Z_FINISH instead of deflateEnd to finish compression. - use Z_FINISH instead of deflateEnd to finish compression
- added Z_HUFFMAN_ONLY - added Z_HUFFMAN_ONLY
- added gzerror() - added gzerror()

View file

@ -1,6 +1,6 @@
ZLIB DATA COMPRESSION LIBRARY ZLIB DATA COMPRESSION LIBRARY
zlib 1.2.11 is a general purpose data compression library. All the code is zlib 1.2.12 is a general purpose data compression library. All the code is
thread safe. The data format used by the zlib library is described by RFCs thread safe. The data format used by the zlib library is described by RFCs
(Request for Comments) 1950 to 1952 in the files (Request for Comments) 1950 to 1952 in the files
http://tools.ietf.org/html/rfc1950 (zlib format), rfc1951 (deflate format) and http://tools.ietf.org/html/rfc1950 (zlib format), rfc1951 (deflate format) and
@ -31,7 +31,7 @@ Mark Nelson <markn@ieee.org> wrote an article about zlib for the Jan. 1997
issue of Dr. Dobb's Journal; a copy of the article is available at issue of Dr. Dobb's Journal; a copy of the article is available at
http://marknelson.us/1997/01/01/zlib-engine/ . http://marknelson.us/1997/01/01/zlib-engine/ .
The changes made in version 1.2.11 are documented in the file ChangeLog. The changes made in version 1.2.12 are documented in the file ChangeLog.
Unsupported third party contributions are provided in directory contrib/ . Unsupported third party contributions are provided in directory contrib/ .
@ -84,7 +84,7 @@ Acknowledgments:
Copyright notice: Copyright notice:
(C) 1995-2017 Jean-loup Gailly and Mark Adler (C) 1995-2022 Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
@ -108,7 +108,10 @@ Copyright notice:
If you use the zlib library in a product, we would appreciate *not* receiving If you use the zlib library in a product, we would appreciate *not* receiving
lengthy legal documents to sign. The sources are provided for free but without lengthy legal documents to sign. The sources are provided for free but without
warranty of any kind. The library has been entirely written by Jean-loup warranty of any kind. The library has been entirely written by Jean-loup
Gailly and Mark Adler; it does not include third-party code. Gailly and Mark Adler; it does not include third-party code. We make all
contributions to and distributions of this project solely in our personal
capacity, and are not conveying any rights to any intellectual property of
any third parties.
If you redistribute modified sources, we would appreciate that you include in If you redistribute modified sources, we would appreciate that you include in
the file ChangeLog history information documenting your changes. Please read the file ChangeLog history information documenting your changes. Please read

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,5 @@
/* deflate.c -- compress data using the deflation algorithm /* deflate.c -- compress data using the deflation algorithm
* Copyright (C) 1995-2017 Jean-loup Gailly and Mark Adler * Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@ -52,7 +52,7 @@
#include "deflate.h" #include "deflate.h"
const char deflate_copyright[] = const char deflate_copyright[] =
" deflate 1.2.11 Copyright 1995-2017 Jean-loup Gailly and Mark Adler "; " deflate 1.2.12 Copyright 1995-2022 Jean-loup Gailly and Mark Adler ";
/* /*
If you use the zlib library in a product, an acknowledgment is welcome If you use the zlib library in a product, an acknowledgment is welcome
in the documentation of your product. If for some reason you cannot in the documentation of your product. If for some reason you cannot
@ -190,8 +190,11 @@ local const config configuration_table[10] = {
* prev[] will be initialized on the fly. * prev[] will be initialized on the fly.
*/ */
#define CLEAR_HASH(s) \ #define CLEAR_HASH(s) \
s->head[s->hash_size-1] = NIL; \ do { \
zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head)); s->head[s->hash_size-1] = NIL; \
zmemzero((Bytef *)s->head, \
(unsigned)(s->hash_size-1)*sizeof(*s->head)); \
} while (0)
/* =========================================================================== /* ===========================================================================
* Slide the hash table when sliding the window down (could be avoided with 32 * Slide the hash table when sliding the window down (could be avoided with 32
@ -252,11 +255,6 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
int wrap = 1; int wrap = 1;
static const char my_version[] = ZLIB_VERSION; static const char my_version[] = ZLIB_VERSION;
ushf *overlay;
/* We overlay pending_buf and d_buf+l_buf. This works since the average
* output size for (length,distance) codes is <= 24 bits.
*/
if (version == Z_NULL || version[0] != my_version[0] || if (version == Z_NULL || version[0] != my_version[0] ||
stream_size != sizeof(z_stream)) { stream_size != sizeof(z_stream)) {
return Z_VERSION_ERROR; return Z_VERSION_ERROR;
@ -326,9 +324,47 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2); /* We overlay pending_buf and sym_buf. This works since the average size
s->pending_buf = (uchf *) overlay; * for length/distance pairs over any compressed block is assured to be 31
s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L); * bits or less.
*
* Analysis: The longest fixed codes are a length code of 8 bits plus 5
* extra bits, for lengths 131 to 257. The longest fixed distance codes are
* 5 bits plus 13 extra bits, for distances 16385 to 32768. The longest
* possible fixed-codes length/distance pair is then 31 bits total.
*
* sym_buf starts one-fourth of the way into pending_buf. So there are
* three bytes in sym_buf for every four bytes in pending_buf. Each symbol
* in sym_buf is three bytes -- two for the distance and one for the
* literal/length. As each symbol is consumed, the pointer to the next
* sym_buf value to read moves forward three bytes. From that symbol, up to
* 31 bits are written to pending_buf. The closest the written pending_buf
* bits gets to the next sym_buf symbol to read is just before the last
* code is written. At that time, 31*(n-2) bits have been written, just
* after 24*(n-2) bits have been consumed from sym_buf. sym_buf starts at
* 8*n bits into pending_buf. (Note that the symbol buffer fills when n-1
* symbols are written.) The closest the writing gets to what is unread is
* then n+14 bits. Here n is lit_bufsize, which is 16384 by default, and
* can range from 128 to 32768.
*
* Therefore, at a minimum, there are 142 bits of space between what is
* written and what is read in the overlain buffers, so the symbols cannot
* be overwritten by the compressed data. That space is actually 139 bits,
* due to the three-bit fixed-code block header.
*
* That covers the case where either Z_FIXED is specified, forcing fixed
* codes, or when the use of fixed codes is chosen, because that choice
* results in a smaller compressed block than dynamic codes. That latter
* condition then assures that the above analysis also covers all dynamic
* blocks. A dynamic-code block will only be chosen to be emitted if it has
* fewer bits than a fixed-code block would for the same set of symbols.
* Therefore its average symbol length is assured to be less than 31. So
* the compressed data for a dynamic block also cannot overwrite the
* symbols from which it is being constructed.
*/
s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, 4);
s->pending_buf_size = (ulg)s->lit_bufsize * 4;
if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
s->pending_buf == Z_NULL) { s->pending_buf == Z_NULL) {
@ -337,8 +373,12 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
deflateEnd (strm); deflateEnd (strm);
return Z_MEM_ERROR; return Z_MEM_ERROR;
} }
s->d_buf = overlay + s->lit_bufsize/sizeof(ush); s->sym_buf = s->pending_buf + s->lit_bufsize;
s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize; s->sym_end = (s->lit_bufsize - 1) * 3;
/* We avoid equality with lit_bufsize*3 because of wraparound at 64K
* on 16 bit machines and because stored blocks are restricted to
* 64K-1 bytes.
*/
s->level = level; s->level = level;
s->strategy = strategy; s->strategy = strategy;
@ -488,13 +528,13 @@ int ZEXPORT deflateResetKeep (strm)
#ifdef GZIP #ifdef GZIP
s->wrap == 2 ? GZIP_STATE : s->wrap == 2 ? GZIP_STATE :
#endif #endif
s->wrap ? INIT_STATE : BUSY_STATE; INIT_STATE;
strm->adler = strm->adler =
#ifdef GZIP #ifdef GZIP
s->wrap == 2 ? crc32(0L, Z_NULL, 0) : s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
#endif #endif
adler32(0L, Z_NULL, 0); adler32(0L, Z_NULL, 0);
s->last_flush = Z_NO_FLUSH; s->last_flush = -2;
_tr_init(s); _tr_init(s);
@ -549,7 +589,8 @@ int ZEXPORT deflatePrime (strm, bits, value)
if (deflateStateCheck(strm)) return Z_STREAM_ERROR; if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
s = strm->state; s = strm->state;
if ((Bytef *)(s->d_buf) < s->pending_out + ((Buf_size + 7) >> 3)) if (bits < 0 || bits > 16 ||
s->sym_buf < s->pending_out + ((Buf_size + 7) >> 3))
return Z_BUF_ERROR; return Z_BUF_ERROR;
do { do {
put = Buf_size - s->bi_valid; put = Buf_size - s->bi_valid;
@ -587,12 +628,12 @@ int ZEXPORT deflateParams(strm, level, strategy)
func = configuration_table[s->level].func; func = configuration_table[s->level].func;
if ((strategy != s->strategy || func != configuration_table[level].func) && if ((strategy != s->strategy || func != configuration_table[level].func) &&
s->high_water) { s->last_flush != -2) {
/* Flush the last buffer: */ /* Flush the last buffer: */
int err = deflate(strm, Z_BLOCK); int err = deflate(strm, Z_BLOCK);
if (err == Z_STREAM_ERROR) if (err == Z_STREAM_ERROR)
return err; return err;
if (strm->avail_out == 0) if (strm->avail_in || (s->strstart - s->block_start) + s->lookahead)
return Z_BUF_ERROR; return Z_BUF_ERROR;
} }
if (s->level != level) { if (s->level != level) {
@ -811,6 +852,8 @@ int ZEXPORT deflate (strm, flush)
} }
/* Write the header */ /* Write the header */
if (s->status == INIT_STATE && s->wrap == 0)
s->status = BUSY_STATE;
if (s->status == INIT_STATE) { if (s->status == INIT_STATE) {
/* zlib header */ /* zlib header */
uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8; uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
@ -1108,7 +1151,6 @@ int ZEXPORT deflateCopy (dest, source)
#else #else
deflate_state *ds; deflate_state *ds;
deflate_state *ss; deflate_state *ss;
ushf *overlay;
if (deflateStateCheck(source) || dest == Z_NULL) { if (deflateStateCheck(source) || dest == Z_NULL) {
@ -1128,8 +1170,7 @@ int ZEXPORT deflateCopy (dest, source)
ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte)); ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos)); ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos)); ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2); ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, 4);
ds->pending_buf = (uchf *) overlay;
if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL || if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
ds->pending_buf == Z_NULL) { ds->pending_buf == Z_NULL) {
@ -1143,8 +1184,7 @@ int ZEXPORT deflateCopy (dest, source)
zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size); zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf); ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush); ds->sym_buf = ds->pending_buf + ds->lit_bufsize;
ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
ds->l_desc.dyn_tree = ds->dyn_ltree; ds->l_desc.dyn_tree = ds->dyn_ltree;
ds->d_desc.dyn_tree = ds->dyn_dtree; ds->d_desc.dyn_tree = ds->dyn_dtree;
@ -1513,6 +1553,8 @@ local void fill_window(s)
s->match_start -= wsize; s->match_start -= wsize;
s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
s->block_start -= (long) wsize; s->block_start -= (long) wsize;
if (s->insert > s->strstart)
s->insert = s->strstart;
slide_hash(s); slide_hash(s);
more += wsize; more += wsize;
} }
@ -1742,6 +1784,7 @@ local block_state deflate_stored(s, flush)
s->matches = 2; /* clear hash */ s->matches = 2; /* clear hash */
zmemcpy(s->window, s->strm->next_in - s->w_size, s->w_size); zmemcpy(s->window, s->strm->next_in - s->w_size, s->w_size);
s->strstart = s->w_size; s->strstart = s->w_size;
s->insert = s->strstart;
} }
else { else {
if (s->window_size - s->strstart <= used) { if (s->window_size - s->strstart <= used) {
@ -1750,12 +1793,14 @@ local block_state deflate_stored(s, flush)
zmemcpy(s->window, s->window + s->w_size, s->strstart); zmemcpy(s->window, s->window + s->w_size, s->strstart);
if (s->matches < 2) if (s->matches < 2)
s->matches++; /* add a pending slide_hash() */ s->matches++; /* add a pending slide_hash() */
if (s->insert > s->strstart)
s->insert = s->strstart;
} }
zmemcpy(s->window + s->strstart, s->strm->next_in - used, used); zmemcpy(s->window + s->strstart, s->strm->next_in - used, used);
s->strstart += used; s->strstart += used;
s->insert += MIN(used, s->w_size - s->insert);
} }
s->block_start = s->strstart; s->block_start = s->strstart;
s->insert += MIN(used, s->w_size - s->insert);
} }
if (s->high_water < s->strstart) if (s->high_water < s->strstart)
s->high_water = s->strstart; s->high_water = s->strstart;
@ -1770,7 +1815,7 @@ local block_state deflate_stored(s, flush)
return block_done; return block_done;
/* Fill the window with any remaining input. */ /* Fill the window with any remaining input. */
have = s->window_size - s->strstart - 1; have = s->window_size - s->strstart;
if (s->strm->avail_in > have && s->block_start >= (long)s->w_size) { if (s->strm->avail_in > have && s->block_start >= (long)s->w_size) {
/* Slide the window down. */ /* Slide the window down. */
s->block_start -= s->w_size; s->block_start -= s->w_size;
@ -1779,12 +1824,15 @@ local block_state deflate_stored(s, flush)
if (s->matches < 2) if (s->matches < 2)
s->matches++; /* add a pending slide_hash() */ s->matches++; /* add a pending slide_hash() */
have += s->w_size; /* more space now */ have += s->w_size; /* more space now */
if (s->insert > s->strstart)
s->insert = s->strstart;
} }
if (have > s->strm->avail_in) if (have > s->strm->avail_in)
have = s->strm->avail_in; have = s->strm->avail_in;
if (have) { if (have) {
read_buf(s->strm, s->window + s->strstart, have); read_buf(s->strm, s->window + s->strstart, have);
s->strstart += have; s->strstart += have;
s->insert += MIN(have, s->w_size - s->insert);
} }
if (s->high_water < s->strstart) if (s->high_water < s->strstart)
s->high_water = s->strstart; s->high_water = s->strstart;
@ -1912,7 +1960,7 @@ local block_state deflate_fast(s, flush)
FLUSH_BLOCK(s, 1); FLUSH_BLOCK(s, 1);
return finish_done; return finish_done;
} }
if (s->last_lit) if (s->sym_next)
FLUSH_BLOCK(s, 0); FLUSH_BLOCK(s, 0);
return block_done; return block_done;
} }
@ -2043,7 +2091,7 @@ local block_state deflate_slow(s, flush)
FLUSH_BLOCK(s, 1); FLUSH_BLOCK(s, 1);
return finish_done; return finish_done;
} }
if (s->last_lit) if (s->sym_next)
FLUSH_BLOCK(s, 0); FLUSH_BLOCK(s, 0);
return block_done; return block_done;
} }
@ -2118,7 +2166,7 @@ local block_state deflate_rle(s, flush)
FLUSH_BLOCK(s, 1); FLUSH_BLOCK(s, 1);
return finish_done; return finish_done;
} }
if (s->last_lit) if (s->sym_next)
FLUSH_BLOCK(s, 0); FLUSH_BLOCK(s, 0);
return block_done; return block_done;
} }
@ -2157,7 +2205,7 @@ local block_state deflate_huff(s, flush)
FLUSH_BLOCK(s, 1); FLUSH_BLOCK(s, 1);
return finish_done; return finish_done;
} }
if (s->last_lit) if (s->sym_next)
FLUSH_BLOCK(s, 0); FLUSH_BLOCK(s, 0);
return block_done; return block_done;
} }

View file

@ -1,5 +1,5 @@
/* deflate.h -- internal compression state /* deflate.h -- internal compression state
* Copyright (C) 1995-2016 Jean-loup Gailly * Copyright (C) 1995-2018 Jean-loup Gailly
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@ -217,7 +217,7 @@ typedef struct internal_state {
/* Depth of each subtree used as tie breaker for trees of equal frequency /* Depth of each subtree used as tie breaker for trees of equal frequency
*/ */
uchf *l_buf; /* buffer for literals or lengths */ uchf *sym_buf; /* buffer for distances and literals/lengths */
uInt lit_bufsize; uInt lit_bufsize;
/* Size of match buffer for literals/lengths. There are 4 reasons for /* Size of match buffer for literals/lengths. There are 4 reasons for
@ -239,13 +239,8 @@ typedef struct internal_state {
* - I can't count above 4 * - I can't count above 4
*/ */
uInt last_lit; /* running index in l_buf */ uInt sym_next; /* running index in sym_buf */
uInt sym_end; /* symbol table full when sym_next reaches this */
ushf *d_buf;
/* Buffer for distances. To simplify the code, d_buf and l_buf have
* the same number of elements. To use different lengths, an extra flag
* array would be necessary.
*/
ulg opt_len; /* bit length of current block with optimal trees */ ulg opt_len; /* bit length of current block with optimal trees */
ulg static_len; /* bit length of current block with static trees */ ulg static_len; /* bit length of current block with static trees */
@ -325,20 +320,22 @@ void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
# define _tr_tally_lit(s, c, flush) \ # define _tr_tally_lit(s, c, flush) \
{ uch cc = (c); \ { uch cc = (c); \
s->d_buf[s->last_lit] = 0; \ s->sym_buf[s->sym_next++] = 0; \
s->l_buf[s->last_lit++] = cc; \ s->sym_buf[s->sym_next++] = 0; \
s->sym_buf[s->sym_next++] = cc; \
s->dyn_ltree[cc].Freq++; \ s->dyn_ltree[cc].Freq++; \
flush = (s->last_lit == s->lit_bufsize-1); \ flush = (s->sym_next == s->sym_end); \
} }
# define _tr_tally_dist(s, distance, length, flush) \ # define _tr_tally_dist(s, distance, length, flush) \
{ uch len = (uch)(length); \ { uch len = (uch)(length); \
ush dist = (ush)(distance); \ ush dist = (ush)(distance); \
s->d_buf[s->last_lit] = dist; \ s->sym_buf[s->sym_next++] = dist; \
s->l_buf[s->last_lit++] = len; \ s->sym_buf[s->sym_next++] = dist >> 8; \
s->sym_buf[s->sym_next++] = len; \
dist--; \ dist--; \
s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
s->dyn_dtree[d_code(dist)].Freq++; \ s->dyn_dtree[d_code(dist)].Freq++; \
flush = (s->last_lit == s->lit_bufsize-1); \ flush = (s->sym_next == s->sym_end); \
} }
#else #else
# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)

View file

@ -1,5 +1,5 @@
/* gzguts.h -- zlib internal header definitions for gz* operations /* gzguts.h -- zlib internal header definitions for gz* operations
* Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013, 2016 Mark Adler * Copyright (C) 2004-2019 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@ -39,7 +39,7 @@
# include <io.h> # include <io.h>
#endif #endif
#if defined(_WIN32) || defined(__CYGWIN__) #if defined(_WIN32)
# define WIDECHAR # define WIDECHAR
#endif #endif
@ -190,6 +190,7 @@ typedef struct {
/* just for writing */ /* just for writing */
int level; /* compression level */ int level; /* compression level */
int strategy; /* compression strategy */ int strategy; /* compression strategy */
int reset; /* true if a reset is pending after a Z_FINISH */
/* seek request */ /* seek request */
z_off64_t skip; /* amount to skip (already rewound if backwards) */ z_off64_t skip; /* amount to skip (already rewound if backwards) */
int seek; /* true if seek request pending */ int seek; /* true if seek request pending */

View file

@ -1,5 +1,5 @@
/* infback.c -- inflate using a call-back interface /* infback.c -- inflate using a call-back interface
* Copyright (C) 1995-2016 Mark Adler * Copyright (C) 1995-2022 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@ -477,6 +477,7 @@ void FAR *out_desc;
} }
Tracev((stderr, "inflate: codes ok\n")); Tracev((stderr, "inflate: codes ok\n"));
state->mode = LEN; state->mode = LEN;
/* fallthrough */
case LEN: case LEN:
/* use inflate_fast() if we have enough input and output */ /* use inflate_fast() if we have enough input and output */

View file

@ -70,7 +70,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
code const FAR *dcode; /* local strm->distcode */ code const FAR *dcode; /* local strm->distcode */
unsigned lmask; /* mask for first level of length codes */ unsigned lmask; /* mask for first level of length codes */
unsigned dmask; /* mask for first level of distance codes */ unsigned dmask; /* mask for first level of distance codes */
code here; /* retrieved table entry */ code const *here; /* retrieved table entry */
unsigned op; /* code bits, operation, extra bits, or */ unsigned op; /* code bits, operation, extra bits, or */
/* window position, window bytes to copy */ /* window position, window bytes to copy */
unsigned len; /* match length, unused bytes */ unsigned len; /* match length, unused bytes */
@ -107,20 +107,20 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
hold += (unsigned long)(*in++) << bits; hold += (unsigned long)(*in++) << bits;
bits += 8; bits += 8;
} }
here = lcode[hold & lmask]; here = lcode + (hold & lmask);
dolen: dolen:
op = (unsigned)(here.bits); op = (unsigned)(here->bits);
hold >>= op; hold >>= op;
bits -= op; bits -= op;
op = (unsigned)(here.op); op = (unsigned)(here->op);
if (op == 0) { /* literal */ if (op == 0) { /* literal */
Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? Tracevv((stderr, here->val >= 0x20 && here->val < 0x7f ?
"inflate: literal '%c'\n" : "inflate: literal '%c'\n" :
"inflate: literal 0x%02x\n", here.val)); "inflate: literal 0x%02x\n", here->val));
*out++ = (unsigned char)(here.val); *out++ = (unsigned char)(here->val);
} }
else if (op & 16) { /* length base */ else if (op & 16) { /* length base */
len = (unsigned)(here.val); len = (unsigned)(here->val);
op &= 15; /* number of extra bits */ op &= 15; /* number of extra bits */
if (op) { if (op) {
if (bits < op) { if (bits < op) {
@ -138,14 +138,14 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
hold += (unsigned long)(*in++) << bits; hold += (unsigned long)(*in++) << bits;
bits += 8; bits += 8;
} }
here = dcode[hold & dmask]; here = dcode + (hold & dmask);
dodist: dodist:
op = (unsigned)(here.bits); op = (unsigned)(here->bits);
hold >>= op; hold >>= op;
bits -= op; bits -= op;
op = (unsigned)(here.op); op = (unsigned)(here->op);
if (op & 16) { /* distance base */ if (op & 16) { /* distance base */
dist = (unsigned)(here.val); dist = (unsigned)(here->val);
op &= 15; /* number of extra bits */ op &= 15; /* number of extra bits */
if (bits < op) { if (bits < op) {
hold += (unsigned long)(*in++) << bits; hold += (unsigned long)(*in++) << bits;
@ -264,7 +264,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
} }
} }
else if ((op & 64) == 0) { /* 2nd level distance code */ else if ((op & 64) == 0) { /* 2nd level distance code */
here = dcode[here.val + (hold & ((1U << op) - 1))]; here = dcode + here->val + (hold & ((1U << op) - 1));
goto dodist; goto dodist;
} }
else { else {
@ -274,7 +274,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
} }
} }
else if ((op & 64) == 0) { /* 2nd level length code */ else if ((op & 64) == 0) { /* 2nd level length code */
here = lcode[here.val + (hold & ((1U << op) - 1))]; here = lcode + here->val + (hold & ((1U << op) - 1));
goto dolen; goto dolen;
} }
else if (op & 32) { /* end-of-block */ else if (op & 32) { /* end-of-block */

View file

@ -1,5 +1,5 @@
/* inflate.c -- zlib decompression /* inflate.c -- zlib decompression
* Copyright (C) 1995-2016 Mark Adler * Copyright (C) 1995-2022 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@ -130,6 +130,7 @@ z_streamp strm;
state->mode = HEAD; state->mode = HEAD;
state->last = 0; state->last = 0;
state->havedict = 0; state->havedict = 0;
state->flags = -1;
state->dmax = 32768U; state->dmax = 32768U;
state->head = Z_NULL; state->head = Z_NULL;
state->hold = 0; state->hold = 0;
@ -447,10 +448,10 @@ unsigned copy;
/* check function to use adler32() for zlib or crc32() for gzip */ /* check function to use adler32() for zlib or crc32() for gzip */
#ifdef GUNZIP #ifdef GUNZIP
# define UPDATE(check, buf, len) \ # define UPDATE_CHECK(check, buf, len) \
(state->flags ? crc32(check, buf, len) : adler32(check, buf, len)) (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
#else #else
# define UPDATE(check, buf, len) adler32(check, buf, len) # define UPDATE_CHECK(check, buf, len) adler32(check, buf, len)
#endif #endif
/* check macros for header crc */ /* check macros for header crc */
@ -670,7 +671,6 @@ int flush;
state->mode = FLAGS; state->mode = FLAGS;
break; break;
} }
state->flags = 0; /* expect zlib header */
if (state->head != Z_NULL) if (state->head != Z_NULL)
state->head->done = -1; state->head->done = -1;
if (!(state->wrap & 1) || /* check if zlib header allowed */ if (!(state->wrap & 1) || /* check if zlib header allowed */
@ -697,6 +697,7 @@ int flush;
break; break;
} }
state->dmax = 1U << len; state->dmax = 1U << len;
state->flags = 0; /* indicate zlib header */
Tracev((stderr, "inflate: zlib header ok\n")); Tracev((stderr, "inflate: zlib header ok\n"));
strm->adler = state->check = adler32(0L, Z_NULL, 0); strm->adler = state->check = adler32(0L, Z_NULL, 0);
state->mode = hold & 0x200 ? DICTID : TYPE; state->mode = hold & 0x200 ? DICTID : TYPE;
@ -722,6 +723,7 @@ int flush;
CRC2(state->check, hold); CRC2(state->check, hold);
INITBITS(); INITBITS();
state->mode = TIME; state->mode = TIME;
/* fallthrough */
case TIME: case TIME:
NEEDBITS(32); NEEDBITS(32);
if (state->head != Z_NULL) if (state->head != Z_NULL)
@ -730,6 +732,7 @@ int flush;
CRC4(state->check, hold); CRC4(state->check, hold);
INITBITS(); INITBITS();
state->mode = OS; state->mode = OS;
/* fallthrough */
case OS: case OS:
NEEDBITS(16); NEEDBITS(16);
if (state->head != Z_NULL) { if (state->head != Z_NULL) {
@ -740,6 +743,7 @@ int flush;
CRC2(state->check, hold); CRC2(state->check, hold);
INITBITS(); INITBITS();
state->mode = EXLEN; state->mode = EXLEN;
/* fallthrough */
case EXLEN: case EXLEN:
if (state->flags & 0x0400) { if (state->flags & 0x0400) {
NEEDBITS(16); NEEDBITS(16);
@ -753,6 +757,7 @@ int flush;
else if (state->head != Z_NULL) else if (state->head != Z_NULL)
state->head->extra = Z_NULL; state->head->extra = Z_NULL;
state->mode = EXTRA; state->mode = EXTRA;
/* fallthrough */
case EXTRA: case EXTRA:
if (state->flags & 0x0400) { if (state->flags & 0x0400) {
copy = state->length; copy = state->length;
@ -775,6 +780,7 @@ int flush;
} }
state->length = 0; state->length = 0;
state->mode = NAME; state->mode = NAME;
/* fallthrough */
case NAME: case NAME:
if (state->flags & 0x0800) { if (state->flags & 0x0800) {
if (have == 0) goto inf_leave; if (have == 0) goto inf_leave;
@ -796,6 +802,7 @@ int flush;
state->head->name = Z_NULL; state->head->name = Z_NULL;
state->length = 0; state->length = 0;
state->mode = COMMENT; state->mode = COMMENT;
/* fallthrough */
case COMMENT: case COMMENT:
if (state->flags & 0x1000) { if (state->flags & 0x1000) {
if (have == 0) goto inf_leave; if (have == 0) goto inf_leave;
@ -816,6 +823,7 @@ int flush;
else if (state->head != Z_NULL) else if (state->head != Z_NULL)
state->head->comment = Z_NULL; state->head->comment = Z_NULL;
state->mode = HCRC; state->mode = HCRC;
/* fallthrough */
case HCRC: case HCRC:
if (state->flags & 0x0200) { if (state->flags & 0x0200) {
NEEDBITS(16); NEEDBITS(16);
@ -839,6 +847,7 @@ int flush;
strm->adler = state->check = ZSWAP32(hold); strm->adler = state->check = ZSWAP32(hold);
INITBITS(); INITBITS();
state->mode = DICT; state->mode = DICT;
/* fallthrough */
case DICT: case DICT:
if (state->havedict == 0) { if (state->havedict == 0) {
RESTORE(); RESTORE();
@ -846,8 +855,10 @@ int flush;
} }
strm->adler = state->check = adler32(0L, Z_NULL, 0); strm->adler = state->check = adler32(0L, Z_NULL, 0);
state->mode = TYPE; state->mode = TYPE;
/* fallthrough */
case TYPE: case TYPE:
if (flush == Z_BLOCK || flush == Z_TREES) goto inf_leave; if (flush == Z_BLOCK || flush == Z_TREES) goto inf_leave;
/* fallthrough */
case TYPEDO: case TYPEDO:
if (state->last) { if (state->last) {
BYTEBITS(); BYTEBITS();
@ -898,8 +909,10 @@ int flush;
INITBITS(); INITBITS();
state->mode = COPY_; state->mode = COPY_;
if (flush == Z_TREES) goto inf_leave; if (flush == Z_TREES) goto inf_leave;
/* fallthrough */
case COPY_: case COPY_:
state->mode = COPY; state->mode = COPY;
/* fallthrough */
case COPY: case COPY:
copy = state->length; copy = state->length;
if (copy) { if (copy) {
@ -935,6 +948,7 @@ int flush;
Tracev((stderr, "inflate: table sizes ok\n")); Tracev((stderr, "inflate: table sizes ok\n"));
state->have = 0; state->have = 0;
state->mode = LENLENS; state->mode = LENLENS;
/* fallthrough */
case LENLENS: case LENLENS:
while (state->have < state->ncode) { while (state->have < state->ncode) {
NEEDBITS(3); NEEDBITS(3);
@ -956,6 +970,7 @@ int flush;
Tracev((stderr, "inflate: code lengths ok\n")); Tracev((stderr, "inflate: code lengths ok\n"));
state->have = 0; state->have = 0;
state->mode = CODELENS; state->mode = CODELENS;
/* fallthrough */
case CODELENS: case CODELENS:
while (state->have < state->nlen + state->ndist) { while (state->have < state->nlen + state->ndist) {
for (;;) { for (;;) {
@ -1039,8 +1054,10 @@ int flush;
Tracev((stderr, "inflate: codes ok\n")); Tracev((stderr, "inflate: codes ok\n"));
state->mode = LEN_; state->mode = LEN_;
if (flush == Z_TREES) goto inf_leave; if (flush == Z_TREES) goto inf_leave;
/* fallthrough */
case LEN_: case LEN_:
state->mode = LEN; state->mode = LEN;
/* fallthrough */
case LEN: case LEN:
if (have >= 6 && left >= 258) { if (have >= 6 && left >= 258) {
RESTORE(); RESTORE();
@ -1090,6 +1107,7 @@ int flush;
} }
state->extra = (unsigned)(here.op) & 15; state->extra = (unsigned)(here.op) & 15;
state->mode = LENEXT; state->mode = LENEXT;
/* fallthrough */
case LENEXT: case LENEXT:
if (state->extra) { if (state->extra) {
NEEDBITS(state->extra); NEEDBITS(state->extra);
@ -1100,6 +1118,7 @@ int flush;
Tracevv((stderr, "inflate: length %u\n", state->length)); Tracevv((stderr, "inflate: length %u\n", state->length));
state->was = state->length; state->was = state->length;
state->mode = DIST; state->mode = DIST;
/* fallthrough */
case DIST: case DIST:
for (;;) { for (;;) {
here = state->distcode[BITS(state->distbits)]; here = state->distcode[BITS(state->distbits)];
@ -1127,6 +1146,7 @@ int flush;
state->offset = (unsigned)here.val; state->offset = (unsigned)here.val;
state->extra = (unsigned)(here.op) & 15; state->extra = (unsigned)(here.op) & 15;
state->mode = DISTEXT; state->mode = DISTEXT;
/* fallthrough */
case DISTEXT: case DISTEXT:
if (state->extra) { if (state->extra) {
NEEDBITS(state->extra); NEEDBITS(state->extra);
@ -1143,6 +1163,7 @@ int flush;
#endif #endif
Tracevv((stderr, "inflate: distance %u\n", state->offset)); Tracevv((stderr, "inflate: distance %u\n", state->offset));
state->mode = MATCH; state->mode = MATCH;
/* fallthrough */
case MATCH: case MATCH:
if (left == 0) goto inf_leave; if (left == 0) goto inf_leave;
copy = out - left; copy = out - left;
@ -1202,7 +1223,7 @@ int flush;
state->total += out; state->total += out;
if ((state->wrap & 4) && out) if ((state->wrap & 4) && out)
strm->adler = state->check = strm->adler = state->check =
UPDATE(state->check, put - out, out); UPDATE_CHECK(state->check, put - out, out);
out = left; out = left;
if ((state->wrap & 4) && ( if ((state->wrap & 4) && (
#ifdef GUNZIP #ifdef GUNZIP
@ -1218,10 +1239,11 @@ int flush;
} }
#ifdef GUNZIP #ifdef GUNZIP
state->mode = LENGTH; state->mode = LENGTH;
/* fallthrough */
case LENGTH: case LENGTH:
if (state->wrap && state->flags) { if (state->wrap && state->flags) {
NEEDBITS(32); NEEDBITS(32);
if (hold != (state->total & 0xffffffffUL)) { if ((state->wrap & 4) && hold != (state->total & 0xffffffff)) {
strm->msg = (char *)"incorrect length check"; strm->msg = (char *)"incorrect length check";
state->mode = BAD; state->mode = BAD;
break; break;
@ -1231,6 +1253,7 @@ int flush;
} }
#endif #endif
state->mode = DONE; state->mode = DONE;
/* fallthrough */
case DONE: case DONE:
ret = Z_STREAM_END; ret = Z_STREAM_END;
goto inf_leave; goto inf_leave;
@ -1240,6 +1263,7 @@ int flush;
case MEM: case MEM:
return Z_MEM_ERROR; return Z_MEM_ERROR;
case SYNC: case SYNC:
/* fallthrough */
default: default:
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
} }
@ -1265,7 +1289,7 @@ int flush;
state->total += out; state->total += out;
if ((state->wrap & 4) && out) if ((state->wrap & 4) && out)
strm->adler = state->check = strm->adler = state->check =
UPDATE(state->check, strm->next_out - out, out); UPDATE_CHECK(state->check, strm->next_out - out, out);
strm->data_type = (int)state->bits + (state->last ? 64 : 0) + strm->data_type = (int)state->bits + (state->last ? 64 : 0) +
(state->mode == TYPE ? 128 : 0) + (state->mode == TYPE ? 128 : 0) +
(state->mode == LEN_ || state->mode == COPY_ ? 256 : 0); (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0);
@ -1401,6 +1425,7 @@ int ZEXPORT inflateSync(strm)
z_streamp strm; z_streamp strm;
{ {
unsigned len; /* number of bytes to look at or looked at */ unsigned len; /* number of bytes to look at or looked at */
int flags; /* temporary to save header status */
unsigned long in, out; /* temporary to save total_in and total_out */ unsigned long in, out; /* temporary to save total_in and total_out */
unsigned char buf[4]; /* to restore bit buffer to byte string */ unsigned char buf[4]; /* to restore bit buffer to byte string */
struct inflate_state FAR *state; struct inflate_state FAR *state;
@ -1433,9 +1458,15 @@ z_streamp strm;
/* return no joy or set up to restart inflate() on a new block */ /* return no joy or set up to restart inflate() on a new block */
if (state->have != 4) return Z_DATA_ERROR; if (state->have != 4) return Z_DATA_ERROR;
if (state->flags == -1)
state->wrap = 0; /* if no header yet, treat as raw */
else
state->wrap &= ~4; /* no point in computing a check value now */
flags = state->flags;
in = strm->total_in; out = strm->total_out; in = strm->total_in; out = strm->total_out;
inflateReset(strm); inflateReset(strm);
strm->total_in = in; strm->total_out = out; strm->total_in = in; strm->total_out = out;
state->flags = flags;
state->mode = TYPE; state->mode = TYPE;
return Z_OK; return Z_OK;
} }
@ -1531,7 +1562,7 @@ int check;
if (inflateStateCheck(strm)) return Z_STREAM_ERROR; if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state; state = (struct inflate_state FAR *)strm->state;
if (check) if (check && state->wrap)
state->wrap |= 4; state->wrap |= 4;
else else
state->wrap &= ~4; state->wrap &= ~4;

View file

@ -1,5 +1,5 @@
/* inflate.h -- internal inflate state definition /* inflate.h -- internal inflate state definition
* Copyright (C) 1995-2016 Mark Adler * Copyright (C) 1995-2019 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@ -86,7 +86,8 @@ struct inflate_state {
int wrap; /* bit 0 true for zlib, bit 1 true for gzip, int wrap; /* bit 0 true for zlib, bit 1 true for gzip,
bit 2 true to validate check value */ bit 2 true to validate check value */
int havedict; /* true if dictionary provided */ int havedict; /* true if dictionary provided */
int flags; /* gzip header method and flags (0 if zlib) */ int flags; /* gzip header method and flags, 0 if zlib, or
-1 if raw or no header yet */
unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
unsigned long check; /* protected copy of check value */ unsigned long check; /* protected copy of check value */
unsigned long total; /* protected copy of output count */ unsigned long total; /* protected copy of output count */

View file

@ -1,5 +1,5 @@
/* inftrees.c -- generate Huffman trees for efficient decoding /* inftrees.c -- generate Huffman trees for efficient decoding
* Copyright (C) 1995-2017 Mark Adler * Copyright (C) 1995-2022 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@ -9,7 +9,7 @@
#define MAXBITS 15 #define MAXBITS 15
const char inflate_copyright[] = const char inflate_copyright[] =
" inflate 1.2.11 Copyright 1995-2017 Mark Adler "; " inflate 1.2.12 Copyright 1995-2022 Mark Adler ";
/* /*
If you use the zlib library in a product, an acknowledgment is welcome If you use the zlib library in a product, an acknowledgment is welcome
in the documentation of your product. If for some reason you cannot in the documentation of your product. If for some reason you cannot
@ -62,7 +62,7 @@ unsigned short FAR *work;
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
static const unsigned short lext[31] = { /* Length codes 257..285 extra */ static const unsigned short lext[31] = { /* Length codes 257..285 extra */
16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 77, 202}; 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 199, 202};
static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,

View file

@ -1,5 +1,5 @@
/* trees.c -- output deflated data using Huffman coding /* trees.c -- output deflated data using Huffman coding
* Copyright (C) 1995-2017 Jean-loup Gailly * Copyright (C) 1995-2021 Jean-loup Gailly
* detect_data_type() function provided freely by Cosmin Truta, 2006 * detect_data_type() function provided freely by Cosmin Truta, 2006
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@ -149,7 +149,7 @@ local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
local void compress_block OF((deflate_state *s, const ct_data *ltree, local void compress_block OF((deflate_state *s, const ct_data *ltree,
const ct_data *dtree)); const ct_data *dtree));
local int detect_data_type OF((deflate_state *s)); local int detect_data_type OF((deflate_state *s));
local unsigned bi_reverse OF((unsigned value, int length)); local unsigned bi_reverse OF((unsigned code, int len));
local void bi_windup OF((deflate_state *s)); local void bi_windup OF((deflate_state *s));
local void bi_flush OF((deflate_state *s)); local void bi_flush OF((deflate_state *s));
@ -416,7 +416,7 @@ local void init_block(s)
s->dyn_ltree[END_BLOCK].Freq = 1; s->dyn_ltree[END_BLOCK].Freq = 1;
s->opt_len = s->static_len = 0L; s->opt_len = s->static_len = 0L;
s->last_lit = s->matches = 0; s->sym_next = s->matches = 0;
} }
#define SMALLEST 1 #define SMALLEST 1
@ -870,7 +870,8 @@ void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last)
bi_windup(s); /* align on byte boundary */ bi_windup(s); /* align on byte boundary */
put_short(s, (ush)stored_len); put_short(s, (ush)stored_len);
put_short(s, (ush)~stored_len); put_short(s, (ush)~stored_len);
zmemcpy(s->pending_buf + s->pending, (Bytef *)buf, stored_len); if (stored_len)
zmemcpy(s->pending_buf + s->pending, (Bytef *)buf, stored_len);
s->pending += stored_len; s->pending += stored_len;
#ifdef ZLIB_DEBUG #ifdef ZLIB_DEBUG
s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L; s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
@ -947,7 +948,7 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ", Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len, opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
s->last_lit)); s->sym_next / 3));
if (static_lenb <= opt_lenb) opt_lenb = static_lenb; if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
@ -1016,8 +1017,9 @@ int ZLIB_INTERNAL _tr_tally (s, dist, lc)
unsigned dist; /* distance of matched string */ unsigned dist; /* distance of matched string */
unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */ unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */
{ {
s->d_buf[s->last_lit] = (ush)dist; s->sym_buf[s->sym_next++] = dist;
s->l_buf[s->last_lit++] = (uch)lc; s->sym_buf[s->sym_next++] = dist >> 8;
s->sym_buf[s->sym_next++] = lc;
if (dist == 0) { if (dist == 0) {
/* lc is the unmatched char */ /* lc is the unmatched char */
s->dyn_ltree[lc].Freq++; s->dyn_ltree[lc].Freq++;
@ -1032,30 +1034,7 @@ int ZLIB_INTERNAL _tr_tally (s, dist, lc)
s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++; s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
s->dyn_dtree[d_code(dist)].Freq++; s->dyn_dtree[d_code(dist)].Freq++;
} }
return (s->sym_next == s->sym_end);
#ifdef TRUNCATE_BLOCK
/* Try to guess if it is profitable to stop the current block here */
if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
/* Compute an upper bound for the compressed length */
ulg out_length = (ulg)s->last_lit*8L;
ulg in_length = (ulg)((long)s->strstart - s->block_start);
int dcode;
for (dcode = 0; dcode < D_CODES; dcode++) {
out_length += (ulg)s->dyn_dtree[dcode].Freq *
(5L+extra_dbits[dcode]);
}
out_length >>= 3;
Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
s->last_lit, in_length, out_length,
100L - out_length*100L/in_length));
if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
}
#endif
return (s->last_lit == s->lit_bufsize-1);
/* We avoid equality with lit_bufsize because of wraparound at 64K
* on 16 bit machines and because stored blocks are restricted to
* 64K-1 bytes.
*/
} }
/* =========================================================================== /* ===========================================================================
@ -1068,13 +1047,14 @@ local void compress_block(s, ltree, dtree)
{ {
unsigned dist; /* distance of matched string */ unsigned dist; /* distance of matched string */
int lc; /* match length or unmatched char (if dist == 0) */ int lc; /* match length or unmatched char (if dist == 0) */
unsigned lx = 0; /* running index in l_buf */ unsigned sx = 0; /* running index in sym_buf */
unsigned code; /* the code to send */ unsigned code; /* the code to send */
int extra; /* number of extra bits to send */ int extra; /* number of extra bits to send */
if (s->last_lit != 0) do { if (s->sym_next != 0) do {
dist = s->d_buf[lx]; dist = s->sym_buf[sx++] & 0xff;
lc = s->l_buf[lx++]; dist += (unsigned)(s->sym_buf[sx++] & 0xff) << 8;
lc = s->sym_buf[sx++];
if (dist == 0) { if (dist == 0) {
send_code(s, lc, ltree); /* send a literal byte */ send_code(s, lc, ltree); /* send a literal byte */
Tracecv(isgraph(lc), (stderr," '%c' ", lc)); Tracecv(isgraph(lc), (stderr," '%c' ", lc));
@ -1099,11 +1079,10 @@ local void compress_block(s, ltree, dtree)
} }
} /* literal or match pair ? */ } /* literal or match pair ? */
/* Check that the overlay between pending_buf and d_buf+l_buf is ok: */ /* Check that the overlay between pending_buf and sym_buf is ok: */
Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx, Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow");
"pendingBuf overflow");
} while (lx < s->last_lit); } while (sx < s->sym_next);
send_code(s, END_BLOCK, ltree); send_code(s, END_BLOCK, ltree);
} }
@ -1112,9 +1091,9 @@ local void compress_block(s, ltree, dtree)
* Check if the data type is TEXT or BINARY, using the following algorithm: * Check if the data type is TEXT or BINARY, using the following algorithm:
* - TEXT if the two conditions below are satisfied: * - TEXT if the two conditions below are satisfied:
* a) There are no non-portable control characters belonging to the * a) There are no non-portable control characters belonging to the
* "black list" (0..6, 14..25, 28..31). * "block list" (0..6, 14..25, 28..31).
* b) There is at least one printable character belonging to the * b) There is at least one printable character belonging to the
* "white list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255). * "allow list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255).
* - BINARY otherwise. * - BINARY otherwise.
* - The following partially-portable control characters form a * - The following partially-portable control characters form a
* "gray list" that is ignored in this detection algorithm: * "gray list" that is ignored in this detection algorithm:
@ -1124,19 +1103,19 @@ local void compress_block(s, ltree, dtree)
local int detect_data_type(s) local int detect_data_type(s)
deflate_state *s; deflate_state *s;
{ {
/* black_mask is the bit mask of black-listed bytes /* block_mask is the bit mask of block-listed bytes
* set bits 0..6, 14..25, and 28..31 * set bits 0..6, 14..25, and 28..31
* 0xf3ffc07f = binary 11110011111111111100000001111111 * 0xf3ffc07f = binary 11110011111111111100000001111111
*/ */
unsigned long black_mask = 0xf3ffc07fUL; unsigned long block_mask = 0xf3ffc07fUL;
int n; int n;
/* Check for non-textual ("black-listed") bytes. */ /* Check for non-textual ("block-listed") bytes. */
for (n = 0; n <= 31; n++, black_mask >>= 1) for (n = 0; n <= 31; n++, block_mask >>= 1)
if ((black_mask & 1) && (s->dyn_ltree[n].Freq != 0)) if ((block_mask & 1) && (s->dyn_ltree[n].Freq != 0))
return Z_BINARY; return Z_BINARY;
/* Check for textual ("white-listed") bytes. */ /* Check for textual ("allow-listed") bytes. */
if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0 if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0
|| s->dyn_ltree[13].Freq != 0) || s->dyn_ltree[13].Freq != 0)
return Z_TEXT; return Z_TEXT;
@ -1144,7 +1123,7 @@ local int detect_data_type(s)
if (s->dyn_ltree[n].Freq != 0) if (s->dyn_ltree[n].Freq != 0)
return Z_TEXT; return Z_TEXT;
/* There are no "black-listed" or "white-listed" bytes: /* There are no "block-listed" or "allow-listed" bytes:
* this stream either is empty or has tolerated ("gray-listed") bytes only. * this stream either is empty or has tolerated ("gray-listed") bytes only.
*/ */
return Z_BINARY; return Z_BINARY;

View file

@ -69,6 +69,7 @@ EXPORTS
gzoffset64 gzoffset64
adler32_combine64 adler32_combine64
crc32_combine64 crc32_combine64
crc32_combine_gen64
; checksum functions ; checksum functions
adler32 adler32
adler32_z adler32_z
@ -76,6 +77,8 @@ EXPORTS
crc32_z crc32_z
adler32_combine adler32_combine
crc32_combine crc32_combine
crc32_combine_gen
crc32_combine_op
; various hacks, don't look :) ; various hacks, don't look :)
deflateInit_ deflateInit_
deflateInit2_ deflateInit2_

Binary file not shown.

View file

@ -1,7 +1,7 @@
/* zlib.h -- interface of the 'zlib' general purpose compression library /* zlib.h -- interface of the 'zlib' general purpose compression library
version 1.2.11, January 15th, 2017 version 1.2.12, March 11th, 2022
Copyright (C) 1995-2017 Jean-loup Gailly and Mark Adler Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
@ -37,11 +37,11 @@
extern "C" { extern "C" {
#endif #endif
#define ZLIB_VERSION "1.2.11" #define ZLIB_VERSION "1.2.12"
#define ZLIB_VERNUM 0x12b0 #define ZLIB_VERNUM 0x12c0
#define ZLIB_VER_MAJOR 1 #define ZLIB_VER_MAJOR 1
#define ZLIB_VER_MINOR 2 #define ZLIB_VER_MINOR 2
#define ZLIB_VER_REVISION 11 #define ZLIB_VER_REVISION 12
#define ZLIB_VER_SUBREVISION 0 #define ZLIB_VER_SUBREVISION 0
/* /*
@ -543,8 +543,7 @@ ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
int strategy)); int strategy));
This is another version of deflateInit with more compression options. The This is another version of deflateInit with more compression options. The
fields next_in, zalloc, zfree and opaque must be initialized before by the fields zalloc, zfree and opaque must be initialized before by the caller.
caller.
The method parameter is the compression method. It must be Z_DEFLATED in The method parameter is the compression method. It must be Z_DEFLATED in
this version of the library. this version of the library.
@ -712,11 +711,12 @@ ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
used to switch between compression and straight copy of the input data, or used to switch between compression and straight copy of the input data, or
to switch to a different kind of input data requiring a different strategy. to switch to a different kind of input data requiring a different strategy.
If the compression approach (which is a function of the level) or the If the compression approach (which is a function of the level) or the
strategy is changed, and if any input has been consumed in a previous strategy is changed, and if there have been any deflate() calls since the
deflate() call, then the input available so far is compressed with the old state was initialized or reset, then the input available so far is
level and strategy using deflate(strm, Z_BLOCK). There are three approaches compressed with the old level and strategy using deflate(strm, Z_BLOCK).
for the compression levels 0, 1..3, and 4..9 respectively. The new level There are three approaches for the compression levels 0, 1..3, and 4..9
and strategy will take effect at the next call of deflate(). respectively. The new level and strategy will take effect at the next call
of deflate().
If a deflate(strm, Z_BLOCK) is performed by deflateParams(), and it does If a deflate(strm, Z_BLOCK) is performed by deflateParams(), and it does
not have enough output space to complete, then the parameter change will not not have enough output space to complete, then the parameter change will not
@ -865,9 +865,11 @@ ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
detection, or add 16 to decode only the gzip format (the zlib format will detection, or add 16 to decode only the gzip format (the zlib format will
return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a
CRC-32 instead of an Adler-32. Unlike the gunzip utility and gzread() (see CRC-32 instead of an Adler-32. Unlike the gunzip utility and gzread() (see
below), inflate() will not automatically decode concatenated gzip streams. below), inflate() will *not* automatically decode concatenated gzip members.
inflate() will return Z_STREAM_END at the end of the gzip stream. The state inflate() will return Z_STREAM_END at the end of the gzip member. The state
would need to be reset to continue decoding a subsequent gzip stream. would need to be reset to continue decoding a subsequent gzip member. This
*must* be done if there is more data after a gzip member, in order for the
decompression to be compliant with the gzip standard (RFC 1952).
inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_VERSION_ERROR if the zlib library version is incompatible with the memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
@ -1302,14 +1304,14 @@ typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */
/* /*
ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
Opens a gzip (.gz) file for reading or writing. The mode parameter is as Open the gzip (.gz) file at path for reading and decompressing, or
in fopen ("rb" or "wb") but can also include a compression level ("wb9") or compressing and writing. The mode parameter is as in fopen ("rb" or "wb")
a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only but can also include a compression level ("wb9") or a strategy: 'f' for
compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F' filtered data as in "wb6f", 'h' for Huffman-only compression as in "wb1h",
for fixed code compression as in "wb9F". (See the description of 'R' for run-length encoding as in "wb1R", or 'F' for fixed code compression
deflateInit2 for more information about the strategy parameter.) 'T' will as in "wb9F". (See the description of deflateInit2 for more information
request transparent writing or appending with no compression and not using about the strategy parameter.) 'T' will request transparent writing or
the gzip format. appending with no compression and not using the gzip format.
"a" can be used instead of "w" to request that the gzip stream that will "a" can be used instead of "w" to request that the gzip stream that will
be written be appended to the file. "+" will result in an error, since be written be appended to the file. "+" will result in an error, since
@ -1339,9 +1341,9 @@ ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
/* /*
gzdopen associates a gzFile with the file descriptor fd. File descriptors Associate a gzFile with the file descriptor fd. File descriptors are
are obtained from calls like open, dup, creat, pipe or fileno (if the file obtained from calls like open, dup, creat, pipe or fileno (if the file has
has been previously opened with fopen). The mode parameter is as in gzopen. been previously opened with fopen). The mode parameter is as in gzopen.
The next call of gzclose on the returned gzFile will also close the file The next call of gzclose on the returned gzFile will also close the file
descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor
@ -1362,13 +1364,13 @@ ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size));
/* /*
Set the internal buffer size used by this library's functions. The Set the internal buffer size used by this library's functions for file to
default buffer size is 8192 bytes. This function must be called after size. The default buffer size is 8192 bytes. This function must be called
gzopen() or gzdopen(), and before any other calls that read or write the after gzopen() or gzdopen(), and before any other calls that read or write
file. The buffer memory allocation is always deferred to the first read or the file. The buffer memory allocation is always deferred to the first read
write. Three times that size in buffer space is allocated. A larger buffer or write. Three times that size in buffer space is allocated. A larger
size of, for example, 64K or 128K bytes will noticeably increase the speed buffer size of, for example, 64K or 128K bytes will noticeably increase the
of decompression (reading). speed of decompression (reading).
The new buffer size also affects the maximum length for gzprintf(). The new buffer size also affects the maximum length for gzprintf().
@ -1378,9 +1380,9 @@ ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size));
ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
/* /*
Dynamically update the compression level or strategy. See the description Dynamically update the compression level and strategy for file. See the
of deflateInit2 for the meaning of these parameters. Previously provided description of deflateInit2 for the meaning of these parameters. Previously
data is flushed before the parameter change. provided data is flushed before applying the parameter changes.
gzsetparams returns Z_OK if success, Z_STREAM_ERROR if the file was not gzsetparams returns Z_OK if success, Z_STREAM_ERROR if the file was not
opened for writing, Z_ERRNO if there is an error writing the flushed data, opened for writing, Z_ERRNO if there is an error writing the flushed data,
@ -1389,7 +1391,7 @@ ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
/* /*
Reads the given number of uncompressed bytes from the compressed file. If Read and decompress up to len uncompressed bytes from file into buf. If
the input file is not in gzip format, gzread copies the given number of the input file is not in gzip format, gzread copies the given number of
bytes into the buffer directly from the file. bytes into the buffer directly from the file.
@ -1420,11 +1422,11 @@ ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
ZEXTERN z_size_t ZEXPORT gzfread OF((voidp buf, z_size_t size, z_size_t nitems, ZEXTERN z_size_t ZEXPORT gzfread OF((voidp buf, z_size_t size, z_size_t nitems,
gzFile file)); gzFile file));
/* /*
Read up to nitems items of size size from file to buf, otherwise operating Read and decompress up to nitems items of size size from file into buf,
as gzread() does. This duplicates the interface of stdio's fread(), with otherwise operating as gzread() does. This duplicates the interface of
size_t request and return types. If the library defines size_t, then stdio's fread(), with size_t request and return types. If the library
z_size_t is identical to size_t. If not, then z_size_t is an unsigned defines size_t, then z_size_t is identical to size_t. If not, then z_size_t
integer type that can contain a pointer. is an unsigned integer type that can contain a pointer.
gzfread() returns the number of full items read of size size, or zero if gzfread() returns the number of full items read of size size, or zero if
the end of the file was reached and a full item could not be read, or if the end of the file was reached and a full item could not be read, or if
@ -1443,18 +1445,16 @@ ZEXTERN z_size_t ZEXPORT gzfread OF((voidp buf, z_size_t size, z_size_t nitems,
file, reseting and retrying on end-of-file, when size is not 1. file, reseting and retrying on end-of-file, when size is not 1.
*/ */
ZEXTERN int ZEXPORT gzwrite OF((gzFile file, ZEXTERN int ZEXPORT gzwrite OF((gzFile file, voidpc buf, unsigned len));
voidpc buf, unsigned len));
/* /*
Writes the given number of uncompressed bytes into the compressed file. Compress and write the len uncompressed bytes at buf to file. gzwrite
gzwrite returns the number of uncompressed bytes written or 0 in case of returns the number of uncompressed bytes written or 0 in case of error.
error.
*/ */
ZEXTERN z_size_t ZEXPORT gzfwrite OF((voidpc buf, z_size_t size, ZEXTERN z_size_t ZEXPORT gzfwrite OF((voidpc buf, z_size_t size,
z_size_t nitems, gzFile file)); z_size_t nitems, gzFile file));
/* /*
gzfwrite() writes nitems items of size size from buf to file, duplicating Compress and write nitems items of size size from buf to file, duplicating
the interface of stdio's fwrite(), with size_t request and return types. If the interface of stdio's fwrite(), with size_t request and return types. If
the library defines size_t, then z_size_t is identical to size_t. If not, the library defines size_t, then z_size_t is identical to size_t. If not,
then z_size_t is an unsigned integer type that can contain a pointer. then z_size_t is an unsigned integer type that can contain a pointer.
@ -1467,22 +1467,22 @@ ZEXTERN z_size_t ZEXPORT gzfwrite OF((voidpc buf, z_size_t size,
ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...)); ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...));
/* /*
Converts, formats, and writes the arguments to the compressed file under Convert, format, compress, and write the arguments (...) to file under
control of the format string, as in fprintf. gzprintf returns the number of control of the string format, as in fprintf. gzprintf returns the number of
uncompressed bytes actually written, or a negative zlib error code in case uncompressed bytes actually written, or a negative zlib error code in case
of error. The number of uncompressed bytes written is limited to 8191, or of error. The number of uncompressed bytes written is limited to 8191, or
one less than the buffer size given to gzbuffer(). The caller should assure one less than the buffer size given to gzbuffer(). The caller should assure
that this limit is not exceeded. If it is exceeded, then gzprintf() will that this limit is not exceeded. If it is exceeded, then gzprintf() will
return an error (0) with nothing written. In this case, there may also be a return an error (0) with nothing written. In this case, there may also be a
buffer overflow with unpredictable consequences, which is possible only if buffer overflow with unpredictable consequences, which is possible only if
zlib was compiled with the insecure functions sprintf() or vsprintf() zlib was compiled with the insecure functions sprintf() or vsprintf(),
because the secure snprintf() or vsnprintf() functions were not available. because the secure snprintf() or vsnprintf() functions were not available.
This can be determined using zlibCompileFlags(). This can be determined using zlibCompileFlags().
*/ */
ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
/* /*
Writes the given null-terminated string to the compressed file, excluding Compress and write the given null-terminated string s to file, excluding
the terminating null character. the terminating null character.
gzputs returns the number of characters written, or -1 in case of error. gzputs returns the number of characters written, or -1 in case of error.
@ -1490,11 +1490,12 @@ ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
/* /*
Reads bytes from the compressed file until len-1 characters are read, or a Read and decompress bytes from file into buf, until len-1 characters are
newline character is read and transferred to buf, or an end-of-file read, or until a newline character is read and transferred to buf, or an
condition is encountered. If any characters are read or if len == 1, the end-of-file condition is encountered. If any characters are read or if len
string is terminated with a null character. If no characters are read due is one, the string is terminated with a null character. If no characters
to an end-of-file or len < 1, then the buffer is left untouched. are read due to an end-of-file or len is less than one, then the buffer is
left untouched.
gzgets returns buf which is a null-terminated string, or it returns NULL gzgets returns buf which is a null-terminated string, or it returns NULL
for end-of-file or in case of error. If there was an error, the contents at for end-of-file or in case of error. If there was an error, the contents at
@ -1503,13 +1504,13 @@ ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
/* /*
Writes c, converted to an unsigned char, into the compressed file. gzputc Compress and write c, converted to an unsigned char, into file. gzputc
returns the value that was written, or -1 in case of error. returns the value that was written, or -1 in case of error.
*/ */
ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
/* /*
Reads one byte from the compressed file. gzgetc returns this byte or -1 Read and decompress one byte from file. gzgetc returns this byte or -1
in case of end of file or error. This is implemented as a macro for speed. in case of end of file or error. This is implemented as a macro for speed.
As such, it does not do all of the checking the other functions do. I.e. As such, it does not do all of the checking the other functions do. I.e.
it does not check to see if file is NULL, nor whether the structure file it does not check to see if file is NULL, nor whether the structure file
@ -1518,8 +1519,8 @@ ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
/* /*
Push one character back onto the stream to be read as the first character Push c back onto the stream for file to be read as the first character on
on the next read. At least one character of push-back is allowed. the next read. At least one character of push-back is always allowed.
gzungetc() returns the character pushed, or -1 on failure. gzungetc() will gzungetc() returns the character pushed, or -1 on failure. gzungetc() will
fail if c is -1, and may fail if a character has been pushed but not read fail if c is -1, and may fail if a character has been pushed but not read
yet. If gzungetc is used immediately after gzopen or gzdopen, at least the yet. If gzungetc is used immediately after gzopen or gzdopen, at least the
@ -1530,9 +1531,9 @@ ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
/* /*
Flushes all pending output into the compressed file. The parameter flush Flush all pending output to file. The parameter flush is as in the
is as in the deflate() function. The return value is the zlib error number deflate() function. The return value is the zlib error number (see function
(see function gzerror below). gzflush is only permitted when writing. gzerror below). gzflush is only permitted when writing.
If the flush parameter is Z_FINISH, the remaining data is written and the If the flush parameter is Z_FINISH, the remaining data is written and the
gzip stream is completed in the output. If gzwrite() is called again, a new gzip stream is completed in the output. If gzwrite() is called again, a new
@ -1547,8 +1548,8 @@ ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
z_off_t offset, int whence)); z_off_t offset, int whence));
Sets the starting position for the next gzread or gzwrite on the given Set the starting position to offset relative to whence for the next gzread
compressed file. The offset represents a number of bytes in the or gzwrite on file. The offset represents a number of bytes in the
uncompressed data stream. The whence parameter is defined as in lseek(2); uncompressed data stream. The whence parameter is defined as in lseek(2);
the value SEEK_END is not supported. the value SEEK_END is not supported.
@ -1565,18 +1566,18 @@ ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
/* /*
Rewinds the given file. This function is supported only for reading. Rewind file. This function is supported only for reading.
gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET).
*/ */
/* /*
ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
Returns the starting position for the next gzread or gzwrite on the given Return the starting position for the next gzread or gzwrite on file.
compressed file. This position represents a number of bytes in the This position represents a number of bytes in the uncompressed data stream,
uncompressed data stream, and is zero when starting, even if appending or and is zero when starting, even if appending or reading a gzip stream from
reading a gzip stream from the middle of a file using gzdopen(). the middle of a file using gzdopen().
gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
*/ */
@ -1584,22 +1585,22 @@ ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
/* /*
ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file)); ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file));
Returns the current offset in the file being read or written. This offset Return the current compressed (actual) read or write offset of file. This
includes the count of bytes that precede the gzip stream, for example when offset includes the count of bytes that precede the gzip stream, for example
appending or when using gzdopen() for reading. When reading, the offset when appending or when using gzdopen() for reading. When reading, the
does not include as yet unused buffered input. This information can be used offset does not include as yet unused buffered input. This information can
for a progress indicator. On error, gzoffset() returns -1. be used for a progress indicator. On error, gzoffset() returns -1.
*/ */
ZEXTERN int ZEXPORT gzeof OF((gzFile file)); ZEXTERN int ZEXPORT gzeof OF((gzFile file));
/* /*
Returns true (1) if the end-of-file indicator has been set while reading, Return true (1) if the end-of-file indicator for file has been set while
false (0) otherwise. Note that the end-of-file indicator is set only if the reading, false (0) otherwise. Note that the end-of-file indicator is set
read tried to go past the end of the input, but came up short. Therefore, only if the read tried to go past the end of the input, but came up short.
just like feof(), gzeof() may return false even if there is no more data to Therefore, just like feof(), gzeof() may return false even if there is no
read, in the event that the last read request was for the exact number of more data to read, in the event that the last read request was for the exact
bytes remaining in the input file. This will happen if the input file size number of bytes remaining in the input file. This will happen if the input
is an exact multiple of the buffer size. file size is an exact multiple of the buffer size.
If gzeof() returns true, then the read functions will return no more data, If gzeof() returns true, then the read functions will return no more data,
unless the end-of-file indicator is reset by gzclearerr() and the input file unless the end-of-file indicator is reset by gzclearerr() and the input file
@ -1608,7 +1609,7 @@ ZEXTERN int ZEXPORT gzeof OF((gzFile file));
ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
/* /*
Returns true (1) if file is being copied directly while reading, or false Return true (1) if file is being copied directly while reading, or false
(0) if file is a gzip stream being decompressed. (0) if file is a gzip stream being decompressed.
If the input file is empty, gzdirect() will return true, since the input If the input file is empty, gzdirect() will return true, since the input
@ -1629,8 +1630,8 @@ ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
ZEXTERN int ZEXPORT gzclose OF((gzFile file)); ZEXTERN int ZEXPORT gzclose OF((gzFile file));
/* /*
Flushes all pending output if necessary, closes the compressed file and Flush all pending output for file, if necessary, close file and
deallocates the (de)compression state. Note that once file is closed, you deallocate the (de)compression state. Note that once file is closed, you
cannot call gzerror with file, since its structures have been deallocated. cannot call gzerror with file, since its structures have been deallocated.
gzclose must not be called more than once on the same file, just as free gzclose must not be called more than once on the same file, just as free
must not be called more than once on the same allocation. must not be called more than once on the same allocation.
@ -1654,10 +1655,10 @@ ZEXTERN int ZEXPORT gzclose_w OF((gzFile file));
ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
/* /*
Returns the error message for the last error which occurred on the given Return the error message for the last error which occurred on file.
compressed file. errnum is set to zlib error number. If an error occurred errnum is set to zlib error number. If an error occurred in the file system
in the file system and not in the compression library, errnum is set to and not in the compression library, errnum is set to Z_ERRNO and the
Z_ERRNO and the application may consult errno to get the exact error code. application may consult errno to get the exact error code.
The application must not modify the returned string. Future calls to The application must not modify the returned string. Future calls to
this function may invalidate the previously returned string. If file is this function may invalidate the previously returned string. If file is
@ -1670,7 +1671,7 @@ ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
/* /*
Clears the error and end-of-file flags for file. This is analogous to the Clear the error and end-of-file flags for file. This is analogous to the
clearerr() function in stdio. This is useful for continuing to read a gzip clearerr() function in stdio. This is useful for continuing to read a gzip
file that is being written concurrently. file that is being written concurrently.
*/ */
@ -1688,8 +1689,9 @@ ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
/* /*
Update a running Adler-32 checksum with the bytes buf[0..len-1] and Update a running Adler-32 checksum with the bytes buf[0..len-1] and
return the updated checksum. If buf is Z_NULL, this function returns the return the updated checksum. An Adler-32 value is in the range of a 32-bit
required initial value for the checksum. unsigned integer. If buf is Z_NULL, this function returns the required
initial value for the checksum.
An Adler-32 checksum is almost as reliable as a CRC-32 but can be computed An Adler-32 checksum is almost as reliable as a CRC-32 but can be computed
much faster. much faster.
@ -1722,12 +1724,13 @@ ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
negative, the result has no meaning or utility. negative, the result has no meaning or utility.
*/ */
ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
/* /*
Update a running CRC-32 with the bytes buf[0..len-1] and return the Update a running CRC-32 with the bytes buf[0..len-1] and return the
updated CRC-32. If buf is Z_NULL, this function returns the required updated CRC-32. A CRC-32 value is in the range of a 32-bit unsigned integer.
initial value for the crc. Pre- and post-conditioning (one's complement) is If buf is Z_NULL, this function returns the required initial value for the
performed within this function so it shouldn't be done by the application. crc. Pre- and post-conditioning (one's complement) is performed within this
function so it shouldn't be done by the application.
Usage example: Usage example:
@ -1739,7 +1742,7 @@ ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
if (crc != original_crc) error(); if (crc != original_crc) error();
*/ */
ZEXTERN uLong ZEXPORT crc32_z OF((uLong adler, const Bytef *buf, ZEXTERN uLong ZEXPORT crc32_z OF((uLong crc, const Bytef *buf,
z_size_t len)); z_size_t len));
/* /*
Same as crc32(), but with a size_t length. Same as crc32(), but with a size_t length.
@ -1755,6 +1758,20 @@ ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
len2. len2.
*/ */
/*
ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t len2));
Return the operator corresponding to length len2, to be used with
crc32_combine_op().
*/
ZEXTERN uLong ZEXPORT crc32_combine_op OF((uLong crc1, uLong crc2, uLong op));
/*
Give the same result as crc32_combine(), using op in place of len2. op is
is generated from len2 by crc32_combine_gen(). This will be faster than
crc32_combine() if the generated op is used more than once.
*/
/* various hacks, don't look :) */ /* various hacks, don't look :) */
@ -1842,6 +1859,7 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */
ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));
ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t)); ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t));
ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t)); ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t));
ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off64_t));
#endif #endif
#if !defined(ZLIB_INTERNAL) && defined(Z_WANT64) #if !defined(ZLIB_INTERNAL) && defined(Z_WANT64)
@ -1852,6 +1870,7 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */
# define z_gzoffset z_gzoffset64 # define z_gzoffset z_gzoffset64
# define z_adler32_combine z_adler32_combine64 # define z_adler32_combine z_adler32_combine64
# define z_crc32_combine z_crc32_combine64 # define z_crc32_combine z_crc32_combine64
# define z_crc32_combine_gen z_crc32_combine_gen64
# else # else
# define gzopen gzopen64 # define gzopen gzopen64
# define gzseek gzseek64 # define gzseek gzseek64
@ -1859,6 +1878,7 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */
# define gzoffset gzoffset64 # define gzoffset gzoffset64
# define adler32_combine adler32_combine64 # define adler32_combine adler32_combine64
# define crc32_combine crc32_combine64 # define crc32_combine crc32_combine64
# define crc32_combine_gen crc32_combine_gen64
# endif # endif
# ifndef Z_LARGE64 # ifndef Z_LARGE64
ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
@ -1867,6 +1887,7 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */
ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile)); ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile));
ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));
ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));
ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off_t));
# endif # endif
#else #else
ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *)); ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *));
@ -1875,12 +1896,14 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */
ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile)); ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile));
ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t));
ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t));
#endif #endif
#else /* Z_SOLO */ #else /* Z_SOLO */
ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t));
ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t));
#endif /* !Z_SOLO */ #endif /* !Z_SOLO */
@ -1893,7 +1916,7 @@ ZEXTERN int ZEXPORT inflateValidate OF((z_streamp, int));
ZEXTERN unsigned long ZEXPORT inflateCodesUsed OF ((z_streamp)); ZEXTERN unsigned long ZEXPORT inflateCodesUsed OF ((z_streamp));
ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp)); ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp));
ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp)); ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp));
#if (defined(_WIN32) || defined(__CYGWIN__)) && !defined(Z_SOLO) #if defined(_WIN32) && !defined(Z_SOLO)
ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path, ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path,
const char *mode)); const char *mode));
#endif #endif

View file

@ -136,8 +136,8 @@ const char * ZEXPORT zError(err)
return ERR_MSG(err); return ERR_MSG(err);
} }
#if defined(_WIN32_WCE) #if defined(_WIN32_WCE) && _WIN32_WCE < 0x800
/* The Microsoft C Run-Time Library for Windows CE doesn't have /* The older Microsoft C Run-Time Library for Windows CE doesn't have
* errno. We define it as a global variable to simplify porting. * errno. We define it as a global variable to simplify porting.
* Its value is always 0 and should not be used. * Its value is always 0 and should not be used.
*/ */

View file

@ -1,5 +1,5 @@
/* zutil.h -- internal interface and configuration of the compression library /* zutil.h -- internal interface and configuration of the compression library
* Copyright (C) 1995-2016 Jean-loup Gailly, Mark Adler * Copyright (C) 1995-2022 Jean-loup Gailly, Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@ -29,10 +29,6 @@
# include <stdlib.h> # include <stdlib.h>
#endif #endif
#ifdef Z_SOLO
typedef long ptrdiff_t; /* guess -- will be caught if guess is wrong */
#endif
#ifndef local #ifndef local
# define local static # define local static
#endif #endif
@ -46,6 +42,17 @@ typedef unsigned short ush;
typedef ush FAR ushf; typedef ush FAR ushf;
typedef unsigned long ulg; typedef unsigned long ulg;
#if !defined(Z_U8) && !defined(Z_SOLO) && defined(STDC)
# include <limits.h>
# if (ULONG_MAX == 0xffffffffffffffff)
# define Z_U8 unsigned long
# elif (ULLONG_MAX == 0xffffffffffffffff)
# define Z_U8 unsigned long long
# elif (UINT_MAX == 0xffffffffffffffff)
# define Z_U8 unsigned
# endif
#endif
extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
/* (size given to avoid silly warnings with Visual C++) */ /* (size given to avoid silly warnings with Visual C++) */
@ -170,10 +177,6 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
#if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX #if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX
# if defined(_WIN32_WCE) # if defined(_WIN32_WCE)
# define fdopen(fd,mode) NULL /* No fdopen() */ # define fdopen(fd,mode) NULL /* No fdopen() */
# ifndef _PTRDIFF_T_DEFINED
typedef int ptrdiff_t;
# define _PTRDIFF_T_DEFINED
# endif
# else # else
# define fdopen(fd,type) _fdopen(fd,type) # define fdopen(fd,type) _fdopen(fd,type)
# endif # endif