From 88e50f170525c0a6237ca5ed4db0c620af366fe7 Mon Sep 17 00:00:00 2001 From: tbeu Date: Tue, 15 Nov 2016 21:04:58 +0100 Subject: [PATCH 01/33] Update miniunz version. --- contrib/minizip/miniunz.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/minizip/miniunz.c b/contrib/minizip/miniunz.c index a12aec8be..8ada038db 100644 --- a/contrib/minizip/miniunz.c +++ b/contrib/minizip/miniunz.c @@ -186,7 +186,7 @@ static int makedir(const char *newdir) { } static void do_banner(void) { - printf("MiniUnz 1.01b, demo of zLib + Unz package written by Gilles Vollant\n"); + printf("MiniUnz 1.1, demo of zLib + Unz package written by Gilles Vollant\n"); printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n"); } From 5af7cef45eeef86ddf6ab00b4e363c1eecaf47b6 Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Thu, 24 Aug 2023 02:14:23 -0400 Subject: [PATCH 02/33] Fix bug in inflateSync() for data held in bit buffer. --- inflate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inflate.c b/inflate.c index b0757a9b2..94ecff015 100644 --- a/inflate.c +++ b/inflate.c @@ -1387,7 +1387,7 @@ int ZEXPORT inflateSync(z_streamp strm) { /* if first time, start search in bit buffer */ if (state->mode != SYNC) { state->mode = SYNC; - state->hold <<= state->bits & 7; + state->hold >>= state->bits & 7; state->bits -= state->bits & 7; len = 0; while (state->bits >= 8) { From bd9c329c1055a9265812352655ed2eec93f36e92 Mon Sep 17 00:00:00 2001 From: Xin LI Date: Sun, 3 Sep 2023 13:10:10 -0700 Subject: [PATCH 03/33] Make internal functions static in the test code. To avoid warnings when building with -Wmissing-prototypes. --- test/example.c | 25 +++++++++++++------------ test/minigzip.c | 30 +++++++++++++++--------------- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/test/example.c b/test/example.c index 582a17a3c..c3521dd59 100644 --- a/test/example.c +++ b/test/example.c @@ -36,12 +36,12 @@ static uLong dictId; /* Adler32 value of the dictionary */ #ifdef Z_SOLO -void *myalloc(void *q, unsigned n, unsigned m) { +static void *myalloc(void *q, unsigned n, unsigned m) { (void)q; return calloc(n, m); } -void myfree(void *q, void *p) { +static void myfree(void *q, void *p) { (void)q; free(p); } @@ -57,7 +57,7 @@ static free_func zfree = (free_func)0; /* =========================================================================== * Test compress() and uncompress() */ -void test_compress(Byte *compr, uLong comprLen, Byte *uncompr, +static void test_compress(Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen) { int err; uLong len = (uLong)strlen(hello)+1; @@ -81,7 +81,7 @@ void test_compress(Byte *compr, uLong comprLen, Byte *uncompr, /* =========================================================================== * Test read/write of .gz files */ -void test_gzio(const char *fname, Byte *uncompr, uLong uncomprLen) { +static void test_gzio(const char *fname, Byte *uncompr, uLong uncomprLen) { #ifdef NO_GZCOMPRESS fprintf(stderr, "NO_GZCOMPRESS -- gz* functions cannot compress\n"); #else @@ -163,7 +163,7 @@ void test_gzio(const char *fname, Byte *uncompr, uLong uncomprLen) { /* =========================================================================== * Test deflate() with small buffers */ -void test_deflate(Byte *compr, uLong comprLen) { +static void test_deflate(Byte *compr, uLong comprLen) { z_stream c_stream; /* compression stream */ int err; uLong len = (uLong)strlen(hello)+1; @@ -198,7 +198,7 @@ void test_deflate(Byte *compr, uLong comprLen) { /* =========================================================================== * Test inflate() with small buffers */ -void test_inflate(Byte *compr, uLong comprLen, Byte *uncompr, +static void test_inflate(Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen) { int err; z_stream d_stream; /* decompression stream */ @@ -237,7 +237,7 @@ void test_inflate(Byte *compr, uLong comprLen, Byte *uncompr, /* =========================================================================== * Test deflate() with large buffers and dynamic change of compression level */ -void test_large_deflate(Byte *compr, uLong comprLen, Byte *uncompr, +static void test_large_deflate(Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen) { z_stream c_stream; /* compression stream */ int err; @@ -290,7 +290,7 @@ void test_large_deflate(Byte *compr, uLong comprLen, Byte *uncompr, /* =========================================================================== * Test inflate() with large buffers */ -void test_large_inflate(Byte *compr, uLong comprLen, Byte *uncompr, +static void test_large_inflate(Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen) { int err; z_stream d_stream; /* decompression stream */ @@ -329,7 +329,7 @@ void test_large_inflate(Byte *compr, uLong comprLen, Byte *uncompr, /* =========================================================================== * Test deflate() with full flush */ -void test_flush(Byte *compr, uLong *comprLen) { +static void test_flush(Byte *compr, uLong *comprLen) { z_stream c_stream; /* compression stream */ int err; uInt len = (uInt)strlen(hello)+1; @@ -364,7 +364,8 @@ void test_flush(Byte *compr, uLong *comprLen) { /* =========================================================================== * Test inflateSync() */ -void test_sync(Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen) { +static void test_sync(Byte *compr, uLong comprLen, Byte *uncompr, + uLong uncomprLen) { int err; z_stream d_stream; /* decompression stream */ @@ -404,7 +405,7 @@ void test_sync(Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen) { /* =========================================================================== * Test deflate() with preset dictionary */ -void test_dict_deflate(Byte *compr, uLong comprLen) { +static void test_dict_deflate(Byte *compr, uLong comprLen) { z_stream c_stream; /* compression stream */ int err; @@ -438,7 +439,7 @@ void test_dict_deflate(Byte *compr, uLong comprLen) { /* =========================================================================== * Test inflate() with a preset dictionary */ -void test_dict_inflate(Byte *compr, uLong comprLen, Byte *uncompr, +static void test_dict_inflate(Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen) { int err; z_stream d_stream; /* decompression stream */ diff --git a/test/minigzip.c b/test/minigzip.c index 8a21ddfb5..c72356dbc 100644 --- a/test/minigzip.c +++ b/test/minigzip.c @@ -149,12 +149,12 @@ static void pwinerror (s) # include /* for unlink() */ #endif -void *myalloc(void *q, unsigned n, unsigned m) { +static void *myalloc(void *q, unsigned n, unsigned m) { (void)q; return calloc(n, m); } -void myfree(void *q, void *p) { +static void myfree(void *q, void *p) { (void)q; free(p); } @@ -167,7 +167,7 @@ typedef struct gzFile_s { z_stream strm; } *gzFile; -gzFile gz_open(const char *path, int fd, const char *mode) { +static gzFile gz_open(const char *path, int fd, const char *mode) { gzFile gz; int ret; @@ -201,15 +201,15 @@ gzFile gz_open(const char *path, int fd, const char *mode) { return gz; } -gzFile gzopen(const char *path, const char *mode) { +static gzFile gzopen(const char *path, const char *mode) { return gz_open(path, -1, mode); } -gzFile gzdopen(int fd, const char *mode) { +static gzFile gzdopen(int fd, const char *mode) { return gz_open(NULL, fd, mode); } -int gzwrite(gzFile gz, const void *buf, unsigned len) { +static int gzwrite(gzFile gz, const void *buf, unsigned len) { z_stream *strm; unsigned char out[BUFLEN]; @@ -227,7 +227,7 @@ int gzwrite(gzFile gz, const void *buf, unsigned len) { return len; } -int gzread(gzFile gz, void *buf, unsigned len) { +static int gzread(gzFile gz, void *buf, unsigned len) { int ret; unsigned got; unsigned char in[1]; @@ -258,7 +258,7 @@ int gzread(gzFile gz, void *buf, unsigned len) { return len - strm->avail_out; } -int gzclose(gzFile gz) { +static int gzclose(gzFile gz) { z_stream *strm; unsigned char out[BUFLEN]; @@ -283,7 +283,7 @@ int gzclose(gzFile gz) { return Z_OK; } -const char *gzerror(gzFile gz, int *err) { +static const char *gzerror(gzFile gz, int *err) { *err = gz->err; return gz->msg; } @@ -295,7 +295,7 @@ static char *prog; /* =========================================================================== * Display error message and exit */ -void error(const char *msg) { +static void error(const char *msg) { fprintf(stderr, "%s: %s\n", prog, msg); exit(1); } @@ -305,7 +305,7 @@ void error(const char *msg) { /* Try compressing the input file at once using mmap. Return Z_OK if * if success, Z_ERRNO otherwise. */ -int gz_compress_mmap(FILE *in, gzFile out) { +static int gz_compress_mmap(FILE *in, gzFile out) { int len; int err; int ifd = fileno(in); @@ -338,7 +338,7 @@ int gz_compress_mmap(FILE *in, gzFile out) { * Compress input to output then close both files. */ -void gz_compress(FILE *in, gzFile out) { +static void gz_compress(FILE *in, gzFile out) { local char buf[BUFLEN]; int len; int err; @@ -366,7 +366,7 @@ void gz_compress(FILE *in, gzFile out) { /* =========================================================================== * Uncompress input to output then close both files. */ -void gz_uncompress(gzFile in, FILE *out) { +static void gz_uncompress(gzFile in, FILE *out) { local char buf[BUFLEN]; int len; int err; @@ -390,7 +390,7 @@ void gz_uncompress(gzFile in, FILE *out) { * Compress the given file: create a corresponding .gz file and remove the * original. */ -void file_compress(char *file, char *mode) { +static void file_compress(char *file, char *mode) { local char outfile[MAX_NAME_LEN]; FILE *in; gzFile out; @@ -426,7 +426,7 @@ void file_compress(char *file, char *mode) { /* =========================================================================== * Uncompress the given file and remove the original. */ -void file_uncompress(char *file) { +static void file_uncompress(char *file) { local char buf[MAX_NAME_LEN]; char *infile, *outfile; FILE *out; From ac8f12c97d1afd9bafa9c710f827d40a407d3266 Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Mon, 18 Sep 2023 21:17:00 -0700 Subject: [PATCH 04/33] Add LIT_MEM define to use more memory for a small deflate speedup. A bug fix in zlib 1.2.12 resulted in a slight slowdown (1-2%) of deflate. This commit provides the option to #define LIT_MEM, which uses more memory to reverse most of that slowdown. The memory for the pending buffer and symbol buffers is increased by 25%, which increases the total memory usage with the default parameters by about 6%. --- deflate.c | 21 +++++++++++++++++++++ deflate.h | 31 ++++++++++++++++++++++++++++++- trees.c | 18 ++++++++++++++++-- 3 files changed, 67 insertions(+), 3 deletions(-) diff --git a/deflate.c b/deflate.c index 5e72cd926..263bbc8d4 100644 --- a/deflate.c +++ b/deflate.c @@ -493,7 +493,11 @@ int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, * symbols from which it is being constructed. */ +#ifdef LIT_MEM + s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, 5); +#else s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, 4); +#endif s->pending_buf_size = (ulg)s->lit_bufsize * 4; if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || @@ -503,8 +507,14 @@ int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, deflateEnd (strm); return Z_MEM_ERROR; } +#ifdef LIT_MEM + s->d_buf = (ushf *)(s->pending_buf + (s->lit_bufsize << 1)); + s->l_buf = s->pending_buf + (s->lit_bufsize << 2); + s->sym_end = s->lit_bufsize - 1; +#else s->sym_buf = s->pending_buf + s->lit_bufsize; s->sym_end = (s->lit_bufsize - 1) * 3; +#endif /* 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. @@ -720,9 +730,15 @@ int ZEXPORT deflatePrime(z_streamp strm, int bits, int value) { if (deflateStateCheck(strm)) return Z_STREAM_ERROR; s = strm->state; +#ifdef LIT_MEM + if (bits < 0 || bits > 16 || + (uchf *)s->d_buf < s->pending_out + ((Buf_size + 7) >> 3)) + return Z_BUF_ERROR; +#else if (bits < 0 || bits > 16 || s->sym_buf < s->pending_out + ((Buf_size + 7) >> 3)) return Z_BUF_ERROR; +#endif do { put = Buf_size - s->bi_valid; if (put > bits) @@ -1308,7 +1324,12 @@ int ZEXPORT deflateCopy(z_streamp dest, z_streamp source) { zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size); ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf); +#ifdef LIT_MEM + ds->d_buf = (ushf *)(ds->pending_buf + (ds->lit_bufsize << 1)); + ds->l_buf = ds->pending_buf + (ds->lit_bufsize << 2); +#else ds->sym_buf = ds->pending_buf + ds->lit_bufsize; +#endif ds->l_desc.dyn_tree = ds->dyn_ltree; ds->d_desc.dyn_tree = ds->dyn_dtree; diff --git a/deflate.h b/deflate.h index 869679142..69fe3a934 100644 --- a/deflate.h +++ b/deflate.h @@ -23,6 +23,10 @@ # define GZIP #endif +/* define LIT_MEM to slightly increase the speed of deflate (order 1% to 2%) at + the cost of a larger memory footprint */ +/* #define LIT_MEM */ + /* =========================================================================== * Internal compression state. */ @@ -217,7 +221,12 @@ typedef struct internal_state { /* Depth of each subtree used as tie breaker for trees of equal frequency */ +#ifdef LIT_MEM + ushf *d_buf; /* buffer for distances */ + uchf *l_buf; /* buffer for literals/lengths */ +#else uchf *sym_buf; /* buffer for distances and literals/lengths */ +#endif uInt lit_bufsize; /* Size of match buffer for literals/lengths. There are 4 reasons for @@ -239,7 +248,7 @@ typedef struct internal_state { * - I can't count above 4 */ - uInt sym_next; /* running index in sym_buf */ + uInt sym_next; /* running index in symbol buffer */ uInt sym_end; /* symbol table full when sym_next reaches this */ ulg opt_len; /* bit length of current block with optimal trees */ @@ -318,6 +327,25 @@ void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf, extern const uch ZLIB_INTERNAL _dist_code[]; #endif +#ifdef LIT_MEM +# define _tr_tally_lit(s, c, flush) \ + { uch cc = (c); \ + s->d_buf[s->sym_next] = 0; \ + s->l_buf[s->sym_next++] = cc; \ + s->dyn_ltree[cc].Freq++; \ + flush = (s->sym_next == s->sym_end); \ + } +# define _tr_tally_dist(s, distance, length, flush) \ + { uch len = (uch)(length); \ + ush dist = (ush)(distance); \ + s->d_buf[s->sym_next] = dist; \ + s->l_buf[s->sym_next++] = len; \ + dist--; \ + s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ + s->dyn_dtree[d_code(dist)].Freq++; \ + flush = (s->sym_next == s->sym_end); \ + } +#else # define _tr_tally_lit(s, c, flush) \ { uch cc = (c); \ s->sym_buf[s->sym_next++] = 0; \ @@ -337,6 +365,7 @@ void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf, s->dyn_dtree[d_code(dist)].Freq++; \ flush = (s->sym_next == s->sym_end); \ } +#endif #else # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) # define _tr_tally_dist(s, distance, length, flush) \ diff --git a/trees.c b/trees.c index 8dbdc40ba..5ca23e938 100644 --- a/trees.c +++ b/trees.c @@ -899,14 +899,19 @@ local void compress_block(deflate_state *s, const ct_data *ltree, const ct_data *dtree) { unsigned dist; /* distance of matched string */ int lc; /* match length or unmatched char (if dist == 0) */ - unsigned sx = 0; /* running index in sym_buf */ + unsigned sx = 0; /* running index in symbol buffers */ unsigned code; /* the code to send */ int extra; /* number of extra bits to send */ if (s->sym_next != 0) do { +#ifdef LIT_MEM + dist = s->d_buf[sx]; + lc = s->l_buf[sx++]; +#else dist = s->sym_buf[sx++] & 0xff; dist += (unsigned)(s->sym_buf[sx++] & 0xff) << 8; lc = s->sym_buf[sx++]; +#endif if (dist == 0) { send_code(s, lc, ltree); /* send a literal byte */ Tracecv(isgraph(lc), (stderr," '%c' ", lc)); @@ -931,8 +936,12 @@ local void compress_block(deflate_state *s, const ct_data *ltree, } } /* literal or match pair ? */ - /* Check that the overlay between pending_buf and sym_buf is ok: */ + /* Check for no overlay of pending_buf on needed symbols */ +#ifdef LIT_MEM + Assert(s->pending < (s->lit_bufsize << 1) + sx, "pendingBuf overflow"); +#else Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow"); +#endif } while (sx < s->sym_next); @@ -1082,9 +1091,14 @@ void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf, * the current block must be flushed. */ int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc) { +#ifdef LIT_MEM + s->d_buf[s->sym_next] = (ush)dist; + s->l_buf[s->sym_next++] = (uch)lc; +#else s->sym_buf[s->sym_next++] = (uch)dist; s->sym_buf[s->sym_next++] = (uch)(dist >> 8); s->sym_buf[s->sym_next++] = (uch)lc; +#endif if (dist == 0) { /* lc is the unmatched char */ s->dyn_ltree[lc].Freq++; From 15c45adb76e81a7e3a8a9e17b2a56eb90f668f44 Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Tue, 7 Nov 2023 15:46:41 -0800 Subject: [PATCH 05/33] Fix decision on the emission of Zip64 end records in minizip. The appnote says that if the number of entries in the end record is 0xffff, then the actual number of entries will be found in the Zip64 end record. Therefore if the number of entries is equal to 0xffff, it can't be in the end record by itself, since that is an instruction to get the number from the Zip64 end record. This code would just store 0xffff in the end record in that case, not making a Zip64 end record. This commit fixes that. --- contrib/minizip/zip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/minizip/zip.c b/contrib/minizip/zip.c index 0446109b2..86be90b7c 100644 --- a/contrib/minizip/zip.c +++ b/contrib/minizip/zip.c @@ -1872,7 +1872,7 @@ extern int ZEXPORT zipClose(zipFile file, const char* global_comment) { free_linkedlist(&(zi->central_dir)); pos = centraldir_pos_inzip - zi->add_position_when_writing_offset; - if(pos >= 0xffffffff || zi->number_entry > 0xFFFF) + if(pos >= 0xffffffff || zi->number_entry >= 0xFFFF) { ZPOS64_T Zip64EOCDpos = ZTELL64(zi->z_filefunc,zi->filestream); Write_Zip64EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip); From 643e17b7498d12ab8d15565662880579692f769d Mon Sep 17 00:00:00 2001 From: Paul Ivanov Date: Tue, 14 Nov 2023 16:23:02 -0800 Subject: [PATCH 06/33] Correct repeated words in source file comments and a readme. --- contrib/infback9/inftree9.h | 4 ++-- contrib/minizip/ioapi.h | 2 +- contrib/minizip/zip.c | 4 ++-- contrib/minizip/zip.h | 4 ++-- inftrees.h | 4 ++-- win32/README-WIN32.txt | 4 ++-- zlib.h | 8 ++++---- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/contrib/infback9/inftree9.h b/contrib/infback9/inftree9.h index 2c1252f57..ab2ea28b2 100644 --- a/contrib/infback9/inftree9.h +++ b/contrib/infback9/inftree9.h @@ -41,8 +41,8 @@ typedef struct { examples/enough.c found in the zlib distribution. The arguments to that program are the number of symbols, the initial root table size, and the maximum bit length of a code. "enough 286 9 15" for literal/length codes - returns returns 852, and "enough 32 6 15" for distance codes returns 594. - The initial root table size (9 or 6) is found in the fifth argument of the + returns 852, and "enough 32 6 15" for distance codes returns 594. The + initial root table size (9 or 6) is found in the fifth argument of the inflate_table() calls in infback9.c. If the root table size is changed, then these maximum sizes would be need to be recalculated and updated. */ #define ENOUGH_LENS 852 diff --git a/contrib/minizip/ioapi.h b/contrib/minizip/ioapi.h index c588a18d0..a2d2e6e60 100644 --- a/contrib/minizip/ioapi.h +++ b/contrib/minizip/ioapi.h @@ -144,7 +144,7 @@ typedef long (ZCALLBACK *tell_file_func) (voidpf opaque, voidpf stream) typedef long (ZCALLBACK *seek_file_func) (voidpf opaque, voidpf stream, uLong offset, int origin); -/* here is the "old" 32 bits structure structure */ +/* here is the "old" 32 bits structure */ typedef struct zlib_filefunc_def_s { open_file_func zopen_file; diff --git a/contrib/minizip/zip.c b/contrib/minizip/zip.c index 86be90b7c..e2e9da07c 100644 --- a/contrib/minizip/zip.c +++ b/contrib/minizip/zip.c @@ -614,9 +614,9 @@ local int LoadCentralDirectoryRecord(zip64_internal* pziinit) { ZPOS64_T central_pos; uLong uL; - uLong number_disk; /* number of the current dist, used for + uLong number_disk; /* number of the current disk, used for spanning ZIP, unsupported, always 0*/ - uLong number_disk_with_CD; /* number the the disk with central dir, used + uLong number_disk_with_CD; /* number of the disk with central dir, used for spanning ZIP, unsupported, always 0*/ ZPOS64_T number_entry; ZPOS64_T number_entry_CD; /* total number of entries in diff --git a/contrib/minizip/zip.h b/contrib/minizip/zip.h index 5fc084132..3e230d340 100644 --- a/contrib/minizip/zip.h +++ b/contrib/minizip/zip.h @@ -177,9 +177,9 @@ extern int ZEXPORT zipOpenNewFileInZip64(zipFile file, filename : the filename in zip (if NULL, '-' without quote will be used *zipfi contain supplemental information if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local - contains the extrafield data the the local header + contains the extrafield data for the local header if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global - contains the extrafield data the the local header + contains the extrafield data for the global header if comment != NULL, comment contain the comment string method contain the compression method (0 for store, Z_DEFLATED for deflate) level contain the level of compression (can be Z_DEFAULT_COMPRESSION) diff --git a/inftrees.h b/inftrees.h index a10712d8c..396f74b5d 100644 --- a/inftrees.h +++ b/inftrees.h @@ -41,8 +41,8 @@ typedef struct { examples/enough.c found in the zlib distribution. The arguments to that program are the number of symbols, the initial root table size, and the maximum bit length of a code. "enough 286 9 15" for literal/length codes - returns returns 852, and "enough 30 6 15" for distance codes returns 592. - The initial root table size (9 or 6) is found in the fifth argument of the + returns 852, and "enough 30 6 15" for distance codes returns 592. The + initial root table size (9 or 6) is found in the fifth argument of the inflate_table() calls in inflate.c and infback.c. If the root table size is changed, then these maximum sizes would be need to be recalculated and updated. */ diff --git a/win32/README-WIN32.txt b/win32/README-WIN32.txt index 2790e838c..600fa3f52 100644 --- a/win32/README-WIN32.txt +++ b/win32/README-WIN32.txt @@ -16,8 +16,8 @@ is http://zlib.net/ . Before reporting a problem, please check this site to verify that you have the latest version of zlib; otherwise get the latest version and check whether the problem still exists or not. -PLEASE read DLL_FAQ.txt, and the the zlib FAQ http://zlib.net/zlib_faq.html -before asking for help. +PLEASE read DLL_FAQ.txt, and the zlib FAQ http://zlib.net/zlib_faq.html before +asking for help. Manifest: diff --git a/zlib.h b/zlib.h index ff0fd7e8a..b3e19fce8 100644 --- a/zlib.h +++ b/zlib.h @@ -936,10 +936,10 @@ ZEXTERN int ZEXPORT inflateSync(z_streamp strm); inflateSync returns Z_OK if a possible full flush point has been found, Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point has been found, or Z_STREAM_ERROR if the stream structure was inconsistent. - In the success case, the application may save the current current value of - total_in which indicates where valid compressed data was found. In the - error case, the application may repeatedly call inflateSync, providing more - input each time, until success or end of the input data. + In the success case, the application may save the current value of total_in + which indicates where valid compressed data was found. In the error case, + the application may repeatedly call inflateSync, providing more input each + time, until success or end of the input data. */ ZEXTERN int ZEXPORT inflateCopy(z_streamp dest, From 431a9b65eacab7efabf2230ba97ff426c0e07f9d Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Thu, 7 Dec 2023 06:38:10 -0800 Subject: [PATCH 07/33] Add bounds checking to ERR_MSG() macro, used by zError(). --- zutil.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zutil.h b/zutil.h index 902a304cc..0bd2dbcba 100644 --- a/zutil.h +++ b/zutil.h @@ -56,7 +56,7 @@ typedef unsigned long ulg; extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ /* (size given to avoid silly warnings with Visual C++) */ -#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] +#define ERR_MSG(err) z_errmsg[(err) < -6 || (err) > 2 ? 9 : 2 - (err)] #define ERR_RETURN(strm,err) \ return (strm->msg = ERR_MSG(err), (err)) From 4bd9a71f3539b5ce47f0c67ab5e01f3196dc8ef9 Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Tue, 12 Dec 2023 22:19:05 -0600 Subject: [PATCH 08/33] Remove fdopen #defines in zutil.h. fdopen() is not used by zlib anymore. The #defines are vestigial. --- zutil.h | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/zutil.h b/zutil.h index 0bd2dbcba..bb513cb4b 100644 --- a/zutil.h +++ b/zutil.h @@ -137,17 +137,8 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ # endif #endif -#if defined(MACOS) || defined(TARGET_OS_MAC) +#if defined(MACOS) # define OS_CODE 7 -# ifndef Z_SOLO -# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os -# include /* for fdopen */ -# else -# ifndef fdopen -# define fdopen(fd,mode) NULL /* No fdopen() */ -# endif -# endif -# endif #endif #ifdef __acorn @@ -170,18 +161,6 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ # define OS_CODE 19 #endif -#if defined(_BEOS_) || defined(RISCOS) -# define fdopen(fd,mode) NULL /* No fdopen() */ -#endif - -#if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX -# if defined(_WIN32_WCE) -# define fdopen(fd,mode) NULL /* No fdopen() */ -# else -# define fdopen(fd,type) _fdopen(fd,type) -# endif -#endif - #if defined(__BORLANDC__) && !defined(MSDOS) #pragma warn -8004 #pragma warn -8008 From ee474ff2d11715485a87b123edbdd615ba218b88 Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Fri, 15 Dec 2023 15:10:19 +0100 Subject: [PATCH 09/33] Fix pending buffer overflow assert with LIT_MEM allocation. Since each element in s->d_buf is 2 bytes, the sx index should be multiplied by 2 in the assert. Fixes #897 --- trees.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trees.c b/trees.c index 5ca23e938..e816d32bb 100644 --- a/trees.c +++ b/trees.c @@ -938,7 +938,7 @@ local void compress_block(deflate_state *s, const ct_data *ltree, /* Check for no overlay of pending_buf on needed symbols */ #ifdef LIT_MEM - Assert(s->pending < (s->lit_bufsize << 1) + sx, "pendingBuf overflow"); + Assert(s->pending < 2 * (s->lit_bufsize + sx), "pendingBuf overflow"); #else Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow"); #endif From 60c31985ecdc2b40873564867e1ad2aef0b88697 Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Wed, 20 Dec 2023 12:26:25 +0100 Subject: [PATCH 10/33] Fix the copy of pending_buf in deflateCopy() for the LIT_MEM case. --- deflate.c | 10 +++------- deflate.h | 2 ++ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/deflate.c b/deflate.c index 263bbc8d4..61e34fe80 100644 --- a/deflate.c +++ b/deflate.c @@ -493,11 +493,7 @@ int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, * symbols from which it is being constructed. */ -#ifdef LIT_MEM - s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, 5); -#else - s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, 4); -#endif + s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, LIT_BUFS); s->pending_buf_size = (ulg)s->lit_bufsize * 4; if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || @@ -1310,7 +1306,7 @@ int ZEXPORT deflateCopy(z_streamp dest, z_streamp source) { ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte)); ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos)); ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos)); - ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, 4); + ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, LIT_BUFS); if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL || ds->pending_buf == Z_NULL) { @@ -1321,7 +1317,7 @@ int ZEXPORT deflateCopy(z_streamp dest, z_streamp source) { zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte)); zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos)); zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos)); - zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size); + zmemcpy(ds->pending_buf, ss->pending_buf, ds->lit_bufsize * LIT_BUFS); ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf); #ifdef LIT_MEM diff --git a/deflate.h b/deflate.h index 69fe3a934..854b156ba 100644 --- a/deflate.h +++ b/deflate.h @@ -222,9 +222,11 @@ typedef struct internal_state { */ #ifdef LIT_MEM +# define LIT_BUFS 5 ushf *d_buf; /* buffer for distances */ uchf *l_buf; /* buffer for literals/lengths */ #else +# define LIT_BUFS 4 uchf *sym_buf; /* buffer for distances and literals/lengths */ #endif From 36e369e1a54b35a978dc584496af69a07ec2d71a Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Thu, 11 Jan 2024 12:53:58 -0800 Subject: [PATCH 11/33] Note that the len2 argument of crc_combine*() must be non-negative. If it is negative, then the code will enter an infinite loop. --- zlib.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zlib.h b/zlib.h index b3e19fce8..39991a418 100644 --- a/zlib.h +++ b/zlib.h @@ -1758,14 +1758,14 @@ ZEXTERN uLong ZEXPORT crc32_combine(uLong crc1, uLong crc2, z_off_t len2); seq1 and seq2 with lengths len1 and len2, CRC-32 check values were calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and - len2. + len2. len2 must be non-negative. */ /* ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t len2); Return the operator corresponding to length len2, to be used with - crc32_combine_op(). + crc32_combine_op(). len2 must be non-negative. */ ZEXTERN uLong ZEXPORT crc32_combine_op(uLong crc1, uLong crc2, uLong op); From 762cf49e6368af44dface31e809e69bd4ef7808f Mon Sep 17 00:00:00 2001 From: William Leara Date: Mon, 11 Dec 2023 12:01:52 -0600 Subject: [PATCH 12/33] Refer to correct function in contrib/minizip/unzip.c comment. --- contrib/minizip/unzip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/minizip/unzip.c b/contrib/minizip/unzip.c index ed763f89f..8c42af661 100644 --- a/contrib/minizip/unzip.c +++ b/contrib/minizip/unzip.c @@ -117,7 +117,7 @@ const char unz_copyright[] = " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; -/* unz_file_info_interntal contain internal info about a file in zipfile*/ +/* unz_file_info64_internal contain internal info about a file in zipfile*/ typedef struct unz_file_info64_internal_s { ZPOS64_T offset_curfile;/* relative offset of local header 8 bytes */ From 190168cc1ce9c03c0a4ee296ef13c6d607ced027 Mon Sep 17 00:00:00 2001 From: William Leara Date: Mon, 11 Dec 2023 11:47:43 -0600 Subject: [PATCH 13/33] Correct case of MSDOS in contrib/minizip/miniunz.c. --- contrib/minizip/miniunz.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/minizip/miniunz.c b/contrib/minizip/miniunz.c index 8ada038db..0c2fb0d82 100644 --- a/contrib/minizip/miniunz.c +++ b/contrib/minizip/miniunz.c @@ -79,7 +79,7 @@ /* change_file_date : change the date/time of a file filename : the filename of the file where date/time must be modified - dosdate : the new date at the MSDos format (4 bytes) + dosdate : the new date at the MSDOS format (4 bytes) tmu_date : the SAME new date at the tm_unz format */ static void change_file_date(const char *filename, uLong dosdate, tm_unz tmu_date) { #ifdef _WIN32 From 16799d064b55a6b093fc52364f3343a1b1fa3b2f Mon Sep 17 00:00:00 2001 From: William Leara Date: Mon, 11 Dec 2023 11:32:09 -0600 Subject: [PATCH 14/33] Fix "the the" in examples/gzlog.c. --- examples/gzlog.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/gzlog.c b/examples/gzlog.c index b977802dd..da1b02e73 100644 --- a/examples/gzlog.c +++ b/examples/gzlog.c @@ -212,8 +212,8 @@ to the appropriate recovery below. If there is no foo.add file, provide a zero data length to the recovery. In that case, the append recovery restores the foo.gz to the previous compressed + uncompressed data state. - For the the compress recovery, a missing foo.add file results in foo.gz - being restored to the previous compressed-only data state. + For the compress recovery, a missing foo.add file results in foo.gz being + restored to the previous compressed-only data state. - Append recovery: - Pick up append at + step above - Compress recovery: From 01155ccc3f822a31291a64e4ecd5f1dbb8a8ee63 Mon Sep 17 00:00:00 2001 From: THE-Spellchecker Date: Sat, 2 Dec 2023 16:56:47 -0600 Subject: [PATCH 15/33] Fix random typos over several source and text files. --- contrib/dotzlib/DotZLib/ChecksumImpl.cs | 2 +- contrib/iostream3/zfstream.h | 4 ++-- contrib/minizip/unzip.c | 4 ++-- contrib/minizip/unzip.h | 2 +- contrib/minizip/zip.c | 4 ++-- doc/algorithm.txt | 2 +- examples/zran.c | 2 +- old/visual-basic.txt | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/contrib/dotzlib/DotZLib/ChecksumImpl.cs b/contrib/dotzlib/DotZLib/ChecksumImpl.cs index c1230bf03..de88dcf11 100644 --- a/contrib/dotzlib/DotZLib/ChecksumImpl.cs +++ b/contrib/dotzlib/DotZLib/ChecksumImpl.cs @@ -34,7 +34,7 @@ public ChecksumGeneratorBase() } /// - /// Initializes a new instance of the checksum generator basewith a specified value + /// Initializes a new instance of the checksum generator base with a specified value /// /// The value to set the current checksum to public ChecksumGeneratorBase(uint initialValue) diff --git a/contrib/iostream3/zfstream.h b/contrib/iostream3/zfstream.h index 8574479ae..3dabc0f97 100644 --- a/contrib/iostream3/zfstream.h +++ b/contrib/iostream3/zfstream.h @@ -413,7 +413,7 @@ template class gzomanip2 { public: - // Allows insertor to peek at internals + // Allows inserter to peek at internals template friend gzofstream& operator<<(gzofstream&, @@ -452,7 +452,7 @@ template : func(f), val1(v1), val2(v2) { } -// Insertor applies underlying manipulator function to stream +// Inserter applies underlying manipulator function to stream template inline gzofstream& operator<<(gzofstream& s, const gzomanip2& m) diff --git a/contrib/minizip/unzip.c b/contrib/minizip/unzip.c index 8c42af661..d3c0cead7 100644 --- a/contrib/minizip/unzip.c +++ b/contrib/minizip/unzip.c @@ -450,7 +450,7 @@ local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) return CENTRALDIRINVALID; - /* number of the disk with the start of the zip64 end of central directory */ + /* number of the disk with the start of the zip64 end of central directory */ if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) return CENTRALDIRINVALID; if (uL != 0) @@ -499,7 +499,7 @@ local unzFile unzOpenInternal(const void *path, uLong number_disk; /* number of the current dist, used for spanning ZIP, unsupported, always 0*/ - uLong number_disk_with_CD; /* number the the disk with central dir, used + uLong number_disk_with_CD; /* number the disk with central dir, used for spanning ZIP, unsupported, always 0*/ ZPOS64_T number_entry_CD; /* total number of entries in the central dir diff --git a/contrib/minizip/unzip.h b/contrib/minizip/unzip.h index 14105840f..5cfc9c627 100644 --- a/contrib/minizip/unzip.h +++ b/contrib/minizip/unzip.h @@ -306,7 +306,7 @@ extern int ZEXPORT unzGetCurrentFileInfo(unzFile file, Get Info about the current file if pfile_info!=NULL, the *pfile_info structure will contain some info about the current file - if szFileName!=NULL, the filemane string will be copied in szFileName + if szFileName!=NULL, the filename string will be copied in szFileName (fileNameBufferSize is the size of the buffer) if extraField!=NULL, the extra field information will be copied in extraField (extraFieldBufferSize is the size of the buffer). diff --git a/contrib/minizip/zip.c b/contrib/minizip/zip.c index e2e9da07c..60bdffac3 100644 --- a/contrib/minizip/zip.c +++ b/contrib/minizip/zip.c @@ -575,7 +575,7 @@ local ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK) return 0; - /* number of the disk with the start of the zip64 end of central directory */ + /* number of the disk with the start of the zip64 end of central directory */ if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK) return 0; if (uL != 0) @@ -1608,7 +1608,7 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si if((uLong)(datasize + 4) > zi->ci.size_centralExtraFree) { - // we can not write more data to the buffer that we have room for. + // we cannot write more data to the buffer that we have room for. return ZIP_BADZIPFILE; } diff --git a/doc/algorithm.txt b/doc/algorithm.txt index c97f49502..029e5a313 100644 --- a/doc/algorithm.txt +++ b/doc/algorithm.txt @@ -77,7 +77,7 @@ table took no time (and if you had infinite memory), then there would only be a first level table to cover all the way to the longest code. However, building the table ends up taking a lot longer for more bits since short codes are replicated many times in such a table. What inflate() does is -simply to make the number of bits in the first table a variable, and then +simply to make the number of bits in the first table a variable, and then to set that variable for the maximum speed. For inflate, which has 286 possible codes for the literal/length tree, the size diff --git a/examples/zran.c b/examples/zran.c index 32c93686c..d3135955b 100644 --- a/examples/zran.c +++ b/examples/zran.c @@ -267,7 +267,7 @@ static inline void append_bits(unsigned value, int bits, } } -// Insert enough bits in the form of empty deflate blocks in front of the the +// Insert enough bits in the form of empty deflate blocks in front of the // low bits bits of value, in order to bring the sequence to a byte boundary. // Then feed that to inflate(). This does what inflatePrime() does, except that // a negative value of bits is not supported. bits must be in 0..16. If the diff --git a/old/visual-basic.txt b/old/visual-basic.txt index 57efe5812..3c8d2a42d 100644 --- a/old/visual-basic.txt +++ b/old/visual-basic.txt @@ -115,7 +115,7 @@ SUCCESS Then ReDim Preserve bytaryCpr(lngCprSiz - 1) Open strCprPth For Binary Access Write As #1 Put #1, , bytaryCpr() - Put #1, , lngOriSiz 'Add the the original size value to the end + Put #1, , lngOriSiz 'Add the original size value to the end (last 4 bytes) Close #1 Else From 44dc43ab047d65febed972a17b0e3bf7e994e8f2 Mon Sep 17 00:00:00 2001 From: tbeu Date: Sun, 19 Nov 2023 21:39:14 +0100 Subject: [PATCH 16/33] Add a CMake option to link the C runtime statically. --- CMakeLists.txt | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ae0f8ea29..157097e02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,16 @@ cmake_minimum_required(VERSION 2.4.4...3.15.0) set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON) +if(POLICY CMP0091) + cmake_policy(SET CMP0091 NEW) +endif() + project(zlib C) set(VERSION "1.3.0.1") +option(ZLIB_STATIC_LINK_CRT "Link the MSVC runtime library statically" OFF) + set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables") set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries") set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers") @@ -76,12 +82,24 @@ if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR) endif() set(ZLIB_PC ${CMAKE_CURRENT_BINARY_DIR}/zlib.pc) -configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zlib.pc.cmakein - ${ZLIB_PC} @ONLY) -configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.cmakein - ${CMAKE_CURRENT_BINARY_DIR}/zconf.h @ONLY) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/zlib.pc.cmakein + ${ZLIB_PC} @ONLY) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.cmakein + ${CMAKE_CURRENT_BINARY_DIR}/zconf.h @ONLY) include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}) +if(POLICY CMP0091) + # CMake >= 3.15 has CMAKE_MSVC_RUNTIME_LIBRARY to set the MSVCC runtime library + if(WIN32 AND CMAKE_GENERATOR MATCHES "Visual Studio .*|NMake .*") + if(ZLIB_STATIC_LINK_CRT) + message(STATUS "Configuring to link the MSVC runtime library statically") + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + else() + message(STATUS "Configuring to link the MSVC runtime library dynamically") + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") + endif() + endif() +endif() #============================================================================ # zlib From 14a5f8f266c16c87ab6c086fc52b770b27701e01 Mon Sep 17 00:00:00 2001 From: Matt Wilson Date: Wed, 17 Jan 2024 14:46:18 -0800 Subject: [PATCH 17/33] Neutralize zip file traversal attacks in miniunz. Archive formats such as .zip files are generally susceptible to so-called "traversal attacks". This allows an attacker to craft an archive that writes to unexpected locations of the file system (e.g., /etc/shadow) if an unspecting root user were to unpack a malicious archive. This patch neutralizes absolute paths such as /tmp/moo and deeply relative paths such as dummy/../../../../../../../../../../tmp/moo The Debian project requested CVE-2014-9485 be allocated for the first identified weakness. The fix was incomplete, resulting in a revised patch applied here. Since there wasn't an updated version released by Debian with the incomplete fix, I suggest we use this CVE to identify both issues. Link: https://security.snyk.io/research/zip-slip-vulnerability Link: https://bugs.debian.org/774321 Link: https://bugs.debian.org/776831 Link: https://nvd.nist.gov/vuln/detail/CVE-2014-9485 Reported-by: Jakub Wilk Fixed-by: Michael Gilbert --- contrib/minizip/miniunz.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/contrib/minizip/miniunz.c b/contrib/minizip/miniunz.c index 0c2fb0d82..d627c4226 100644 --- a/contrib/minizip/miniunz.c +++ b/contrib/minizip/miniunz.c @@ -356,6 +356,20 @@ static int do_extract_currentfile(unzFile uf, const int* popt_extract_without_pa else write_filename = filename_withoutpath; + if (write_filename[0]!='\0') + { + const char* relative_check = write_filename; + while (relative_check[1]!='\0') + { + if (relative_check[0]=='.' && relative_check[1]=='.') + write_filename = relative_check; + relative_check++; + } + } + + while (write_filename[0]=='/' || write_filename[0]=='.') + write_filename++; + err = unzOpenCurrentFilePassword(uf,password); if (err!=UNZ_OK) { From 6201f893846bfd22faf060e84a3bb7bfc0e61761 Mon Sep 17 00:00:00 2001 From: Peter Taylor Date: Fri, 10 Feb 2017 18:37:09 +0000 Subject: [PATCH 18/33] Add cmake option to control the build of the example executables. --- CMakeLists.txt | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 157097e02..61188e42b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,7 @@ project(zlib C) set(VERSION "1.3.0.1") +option(ZLIB_BUILD_EXAMPLES "Enable Zlib Examples" ON) option(ZLIB_STATIC_LINK_CRT "Link the MSVC runtime library statically" OFF) set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables") @@ -211,21 +212,22 @@ endif() #============================================================================ # Example binaries #============================================================================ - -add_executable(example test/example.c) -target_link_libraries(example zlib) -add_test(example example) - -add_executable(minigzip test/minigzip.c) -target_link_libraries(minigzip zlib) - -if(HAVE_OFF64_T) - add_executable(example64 test/example.c) - target_link_libraries(example64 zlib) - set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") - add_test(example64 example64) - - add_executable(minigzip64 test/minigzip.c) - target_link_libraries(minigzip64 zlib) - set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") +if(ZLIB_BUILD_EXAMPLES) + add_executable(example test/example.c) + target_link_libraries(example zlib) + add_test(example example) + + add_executable(minigzip test/minigzip.c) + target_link_libraries(minigzip zlib) + + if(HAVE_OFF64_T) + add_executable(example64 test/example.c) + target_link_libraries(example64 zlib) + set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") + add_test(example64 example64) + + add_executable(minigzip64 test/minigzip.c) + target_link_libraries(minigzip64 zlib) + set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") + endif() endif() From 01253ecd7e0a01d311670f2d03c61b82fc12d338 Mon Sep 17 00:00:00 2001 From: Milan Bulat Date: Mon, 9 Oct 2023 17:04:51 +0400 Subject: [PATCH 19/33] Make the existence of gz_intmax() unconditional. gz_intmax() is noted in zlib.map. This assures it's always there. --- gzguts.h | 6 +----- gzlib.c | 10 +++++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/gzguts.h b/gzguts.h index f9375047e..adc2b34fe 100644 --- a/gzguts.h +++ b/gzguts.h @@ -210,9 +210,5 @@ char ZLIB_INTERNAL *gz_strwinerror(DWORD error); /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t value -- needed when comparing unsigned to z_off64_t, which is signed (possible z_off64_t types off_t, off64_t, and long are all signed) */ -#ifdef INT_MAX -# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX) -#else unsigned ZLIB_INTERNAL gz_intmax(void); -# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax()) -#endif +#define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax()) diff --git a/gzlib.c b/gzlib.c index 29fc4486f..9c103dbd1 100644 --- a/gzlib.c +++ b/gzlib.c @@ -563,20 +563,20 @@ void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg) { #endif } -#ifndef INT_MAX /* portably return maximum value for an int (when limits.h presumed not available) -- we need to do this to cover cases where 2's complement not used, since C standard permits 1's complement and sign-bit representations, otherwise we could just use ((unsigned)-1) >> 1 */ unsigned ZLIB_INTERNAL gz_intmax(void) { - unsigned p, q; - - p = 1; +#ifdef INT_MAX + return INT_MAX; +#else + unsigned p = 1, q; do { q = p; p <<= 1; p++; } while (p > q); return q >> 1; -} #endif +} From fe41d1892117fa81bd49f69b1c87d805635b853c Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sun, 6 Aug 2023 13:56:45 +0200 Subject: [PATCH 20/33] Correct typos in source code. --- contrib/minizip/unzip.c | 2 +- contrib/puff/puff.c | 8 ++++---- test/minigzip.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/contrib/minizip/unzip.c b/contrib/minizip/unzip.c index d3c0cead7..ea05b7d62 100644 --- a/contrib/minizip/unzip.c +++ b/contrib/minizip/unzip.c @@ -497,7 +497,7 @@ local unzFile unzOpenInternal(const void *path, ZPOS64_T central_pos; uLong uL; - uLong number_disk; /* number of the current dist, used for + uLong number_disk; /* number of the current disk, used for spanning ZIP, unsupported, always 0*/ uLong number_disk_with_CD; /* number the disk with central dir, used for spanning ZIP, unsupported, always 0*/ diff --git a/contrib/puff/puff.c b/contrib/puff/puff.c index 6737ff615..d759825ab 100644 --- a/contrib/puff/puff.c +++ b/contrib/puff/puff.c @@ -593,10 +593,10 @@ local int fixed(struct state *s) * provided for each of the literal/length symbols, and for each of the * distance symbols. * - * - If a symbol is not used in the block, this is represented by a zero as - * as the code length. This does not mean a zero-length code, but rather - * that no code should be created for this symbol. There is no way in the - * deflate format to represent a zero-length code. + * - If a symbol is not used in the block, this is represented by a zero as the + * code length. This does not mean a zero-length code, but rather that no + * code should be created for this symbol. There is no way in the deflate + * format to represent a zero-length code. * * - The maximum number of bits in a code is 15, so the possible lengths for * any code are 1..15. diff --git a/test/minigzip.c b/test/minigzip.c index c72356dbc..134e10e6c 100644 --- a/test/minigzip.c +++ b/test/minigzip.c @@ -303,7 +303,7 @@ static void error(const char *msg) { #ifdef USE_MMAP /* MMAP version, Miguel Albrecht */ /* Try compressing the input file at once using mmap. Return Z_OK if - * if success, Z_ERRNO otherwise. + * success, Z_ERRNO otherwise. */ static int gz_compress_mmap(FILE *in, gzFile out) { int len; From 25263462377fa5c569947a40315815bd59e37f4b Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Wed, 17 Jan 2024 17:19:03 -0800 Subject: [PATCH 21/33] Remove mentions of an official zlib DLL distribution. There used to be one, but no more. It is up to the user or vendor to compile zlib. --- FAQ | 3 +-- win32/DLL_FAQ.txt | 20 ++------------------ 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/FAQ b/FAQ index 55f1cdc22..92f5d3e29 100644 --- a/FAQ +++ b/FAQ @@ -14,8 +14,7 @@ The latest zlib FAQ is at http://zlib.net/zlib_faq.html 2. Where can I get a Windows DLL version? The zlib sources can be compiled without change to produce a DLL. See the - file win32/DLL_FAQ.txt in the zlib distribution. Pointers to the - precompiled DLL are found in the zlib web site at http://zlib.net/ . + file win32/DLL_FAQ.txt in the zlib distribution. 3. Where can I get a Visual Basic interface to zlib? diff --git a/win32/DLL_FAQ.txt b/win32/DLL_FAQ.txt index 12c009018..d8cf5f31e 100644 --- a/win32/DLL_FAQ.txt +++ b/win32/DLL_FAQ.txt @@ -3,7 +3,7 @@ This document describes the design, the rationale, and the usage -of the official DLL build of zlib, named ZLIB1.DLL. If you have +of the common DLL build of zlib, named ZLIB1.DLL. If you have general questions about zlib, you should see the file "FAQ" found in the zlib distribution, or at the following location: http://www.gzip.org/zlib/zlib_faq.html @@ -11,13 +11,9 @@ in the zlib distribution, or at the following location: 1. What is ZLIB1.DLL, and how can I get it? - - ZLIB1.DLL is the official build of zlib as a DLL. + - ZLIB1.DLL is the common build of zlib as a DLL. (Please remark the character '1' in the name.) - Pointers to a precompiled ZLIB1.DLL can be found in the zlib - web site at: - http://www.zlib.net/ - Applications that link to ZLIB1.DLL can rely on the following specification: @@ -379,18 +375,6 @@ in the zlib distribution, or at the following location: code. But you can make your own private DLL build, under a different file name, as suggested in the previous answer. - -17. I made my own ZLIB1.DLL build. Can I test it for compliance? - - - We prefer that you download the official DLL from the zlib - web site. If you need something peculiar from this DLL, you - can send your suggestion to the zlib mailing list. - - However, in case you do rebuild the DLL yourself, you can run - it with the test programs found in the DLL distribution. - Running these test programs is not a guarantee of compliance, - but a failure can imply a detected problem. - ** This document is written and maintained by From ade6825c4996f73d776b0ffa038360762bd318ae Mon Sep 17 00:00:00 2001 From: gastush Date: Fri, 30 Sep 2022 16:04:19 +0200 Subject: [PATCH 22/33] Fix cmake build on AIX. The --version-script linker option is not supported by the linker on AIX systems --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 61188e42b..6ae4d6f14 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -185,7 +185,7 @@ endif() if(UNIX) # On unix-like platforms the library is almost always called libz set_target_properties(zlib zlibstatic PROPERTIES OUTPUT_NAME z) - if(NOT APPLE) + if(NOT APPLE AND NOT(CMAKE_SYSTEM_NAME STREQUAL AIX)) set_target_properties(zlib PROPERTIES LINK_FLAGS "-Wl,--version-script,\"${CMAKE_CURRENT_SOURCE_DIR}/zlib.map\"") endif() elseif(BUILD_SHARED_LIBS AND WIN32) From 3f635df97edbb85f55f8e991e5f00d94f4132a14 Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Wed, 17 Jan 2024 18:20:32 -0800 Subject: [PATCH 23/33] Remove unused Z_ARG macro. --- zconf.h | 8 -------- zconf.h.cmakein | 8 -------- zconf.h.in | 8 -------- 3 files changed, 24 deletions(-) diff --git a/zconf.h b/zconf.h index fb76ffe31..9baa9527f 100644 --- a/zconf.h +++ b/zconf.h @@ -300,14 +300,6 @@ # endif #endif -#ifndef Z_ARG /* function prototypes for stdarg */ -# if defined(STDC) || defined(Z_HAVE_STDARG_H) -# define Z_ARG(args) args -# else -# define Z_ARG(args) () -# endif -#endif - /* The following definitions for FAR are needed only for MSDOS mixed * model programming (small or medium model with some far allocations). * This was tested only with MSC; for other MSDOS compilers you may have diff --git a/zconf.h.cmakein b/zconf.h.cmakein index 310c43928..51558cef9 100644 --- a/zconf.h.cmakein +++ b/zconf.h.cmakein @@ -302,14 +302,6 @@ # endif #endif -#ifndef Z_ARG /* function prototypes for stdarg */ -# if defined(STDC) || defined(Z_HAVE_STDARG_H) -# define Z_ARG(args) args -# else -# define Z_ARG(args) () -# endif -#endif - /* The following definitions for FAR are needed only for MSDOS mixed * model programming (small or medium model with some far allocations). * This was tested only with MSC; for other MSDOS compilers you may have diff --git a/zconf.h.in b/zconf.h.in index fb76ffe31..9baa9527f 100644 --- a/zconf.h.in +++ b/zconf.h.in @@ -300,14 +300,6 @@ # endif #endif -#ifndef Z_ARG /* function prototypes for stdarg */ -# if defined(STDC) || defined(Z_HAVE_STDARG_H) -# define Z_ARG(args) args -# else -# define Z_ARG(args) () -# endif -#endif - /* The following definitions for FAR are needed only for MSDOS mixed * model programming (small or medium model with some far allocations). * This was tested only with MSC; for other MSDOS compilers you may have From 7b632b486a591aa28d3d98d0ed8aa2235ee34643 Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Fri, 19 Jan 2024 10:09:32 -0800 Subject: [PATCH 24/33] Revert "Add a CMake option to link the C runtime statically." This reverts commit 44dc43ab047d65febed972a17b0e3bf7e994e8f2. --- CMakeLists.txt | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ae4d6f14..6fab3dcb1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,16 +1,11 @@ cmake_minimum_required(VERSION 2.4.4...3.15.0) set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON) -if(POLICY CMP0091) - cmake_policy(SET CMP0091 NEW) -endif() - project(zlib C) set(VERSION "1.3.0.1") option(ZLIB_BUILD_EXAMPLES "Enable Zlib Examples" ON) -option(ZLIB_STATIC_LINK_CRT "Link the MSVC runtime library statically" OFF) set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables") set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries") @@ -83,24 +78,12 @@ if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR) endif() set(ZLIB_PC ${CMAKE_CURRENT_BINARY_DIR}/zlib.pc) -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/zlib.pc.cmakein - ${ZLIB_PC} @ONLY) -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.cmakein - ${CMAKE_CURRENT_BINARY_DIR}/zconf.h @ONLY) +configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zlib.pc.cmakein + ${ZLIB_PC} @ONLY) +configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.cmakein + ${CMAKE_CURRENT_BINARY_DIR}/zconf.h @ONLY) include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}) -if(POLICY CMP0091) - # CMake >= 3.15 has CMAKE_MSVC_RUNTIME_LIBRARY to set the MSVCC runtime library - if(WIN32 AND CMAKE_GENERATOR MATCHES "Visual Studio .*|NMake .*") - if(ZLIB_STATIC_LINK_CRT) - message(STATUS "Configuring to link the MSVC runtime library statically") - set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") - else() - message(STATUS "Configuring to link the MSVC runtime library dynamically") - set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") - endif() - endif() -endif() #============================================================================ # zlib From 7af6320ad78b390de42f414fabdc64dc6d67a5ea Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Fri, 19 Jan 2024 12:19:53 -0800 Subject: [PATCH 25/33] Fix a bug in ZLIB_DEBUG compiles in check_match(). This avoids trying to compare a match starting one byte before the current window. Thanks to @zmodem (Hans) for discovering this. --- deflate.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/deflate.c b/deflate.c index 61e34fe80..d73a73eef 100644 --- a/deflate.c +++ b/deflate.c @@ -1556,13 +1556,21 @@ local uInt longest_match(deflate_state *s, IPos cur_match) { */ local void check_match(deflate_state *s, IPos start, IPos match, int length) { /* check that the match is indeed a match */ - if (zmemcmp(s->window + match, - s->window + start, length) != EQUAL) { - fprintf(stderr, " start %u, match %u, length %d\n", - start, match, length); + Bytef *back = s->window + (int)match, *here = s->window + start; + IPos len = length; + if (match == (IPos)-1) { + /* match starts one byte before the current window -- just compare the + subsequent length-1 bytes */ + back++; + here++; + len--; + } + if (zmemcmp(back, here, len) != EQUAL) { + fprintf(stderr, " start %u, match %d, length %d\n", + start, (int)match, length); do { - fprintf(stderr, "%c%c", s->window[match++], s->window[start++]); - } while (--length != 0); + fprintf(stderr, "(%02x %02x)", *back++, *here++); + } while (--len != 0); z_error("invalid match"); } if (z_verbose > 1) { From 84f0bafd7cd76ef3787b8612ea79ba77c489d7bd Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Fri, 19 Jan 2024 15:26:17 -0800 Subject: [PATCH 26/33] Remove carriage returns from zlib.map. --- zlib.map | 200 +++++++++++++++++++++++++++---------------------------- 1 file changed, 100 insertions(+), 100 deletions(-) diff --git a/zlib.map b/zlib.map index b330b606f..31544f2e9 100644 --- a/zlib.map +++ b/zlib.map @@ -1,100 +1,100 @@ -ZLIB_1.2.0 { - global: - compressBound; - deflateBound; - inflateBack; - inflateBackEnd; - inflateBackInit_; - inflateCopy; - local: - deflate_copyright; - inflate_copyright; - inflate_fast; - inflate_table; - zcalloc; - zcfree; - z_errmsg; - gz_error; - gz_intmax; - _*; -}; - -ZLIB_1.2.0.2 { - gzclearerr; - gzungetc; - zlibCompileFlags; -} ZLIB_1.2.0; - -ZLIB_1.2.0.8 { - deflatePrime; -} ZLIB_1.2.0.2; - -ZLIB_1.2.2 { - adler32_combine; - crc32_combine; - deflateSetHeader; - inflateGetHeader; -} ZLIB_1.2.0.8; - -ZLIB_1.2.2.3 { - deflateTune; - gzdirect; -} ZLIB_1.2.2; - -ZLIB_1.2.2.4 { - inflatePrime; -} ZLIB_1.2.2.3; - -ZLIB_1.2.3.3 { - adler32_combine64; - crc32_combine64; - gzopen64; - gzseek64; - gztell64; - inflateUndermine; -} ZLIB_1.2.2.4; - -ZLIB_1.2.3.4 { - inflateReset2; - inflateMark; -} ZLIB_1.2.3.3; - -ZLIB_1.2.3.5 { - gzbuffer; - gzoffset; - gzoffset64; - gzclose_r; - gzclose_w; -} ZLIB_1.2.3.4; - -ZLIB_1.2.5.1 { - deflatePending; -} ZLIB_1.2.3.5; - -ZLIB_1.2.5.2 { - deflateResetKeep; - gzgetc_; - inflateResetKeep; -} ZLIB_1.2.5.1; - -ZLIB_1.2.7.1 { - inflateGetDictionary; - gzvprintf; -} ZLIB_1.2.5.2; - -ZLIB_1.2.9 { - inflateCodesUsed; - inflateValidate; - uncompress2; - gzfread; - gzfwrite; - deflateGetDictionary; - adler32_z; - crc32_z; -} ZLIB_1.2.7.1; - -ZLIB_1.2.12 { - crc32_combine_gen; - crc32_combine_gen64; - crc32_combine_op; -} ZLIB_1.2.9; +ZLIB_1.2.0 { + global: + compressBound; + deflateBound; + inflateBack; + inflateBackEnd; + inflateBackInit_; + inflateCopy; + local: + deflate_copyright; + inflate_copyright; + inflate_fast; + inflate_table; + zcalloc; + zcfree; + z_errmsg; + gz_error; + gz_intmax; + _*; +}; + +ZLIB_1.2.0.2 { + gzclearerr; + gzungetc; + zlibCompileFlags; +} ZLIB_1.2.0; + +ZLIB_1.2.0.8 { + deflatePrime; +} ZLIB_1.2.0.2; + +ZLIB_1.2.2 { + adler32_combine; + crc32_combine; + deflateSetHeader; + inflateGetHeader; +} ZLIB_1.2.0.8; + +ZLIB_1.2.2.3 { + deflateTune; + gzdirect; +} ZLIB_1.2.2; + +ZLIB_1.2.2.4 { + inflatePrime; +} ZLIB_1.2.2.3; + +ZLIB_1.2.3.3 { + adler32_combine64; + crc32_combine64; + gzopen64; + gzseek64; + gztell64; + inflateUndermine; +} ZLIB_1.2.2.4; + +ZLIB_1.2.3.4 { + inflateReset2; + inflateMark; +} ZLIB_1.2.3.3; + +ZLIB_1.2.3.5 { + gzbuffer; + gzoffset; + gzoffset64; + gzclose_r; + gzclose_w; +} ZLIB_1.2.3.4; + +ZLIB_1.2.5.1 { + deflatePending; +} ZLIB_1.2.3.5; + +ZLIB_1.2.5.2 { + deflateResetKeep; + gzgetc_; + inflateResetKeep; +} ZLIB_1.2.5.1; + +ZLIB_1.2.7.1 { + inflateGetDictionary; + gzvprintf; +} ZLIB_1.2.5.2; + +ZLIB_1.2.9 { + inflateCodesUsed; + inflateValidate; + uncompress2; + gzfread; + gzfwrite; + deflateGetDictionary; + adler32_z; + crc32_z; +} ZLIB_1.2.7.1; + +ZLIB_1.2.12 { + crc32_combine_gen; + crc32_combine_gen64; + crc32_combine_op; +} ZLIB_1.2.9; From 9404df5a1f35866d441e8033b34186ca42962ea9 Mon Sep 17 00:00:00 2001 From: Dan Kegel Date: Fri, 22 May 2020 14:35:01 -0700 Subject: [PATCH 27/33] Use updated zconf.h when building out of directory with configure. --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index 7aaf5dfa3..0b86d04e0 100755 --- a/configure +++ b/configure @@ -25,7 +25,7 @@ if test $SRCDIR = "."; then ZINCOUT="-I." SRCDIR="" else - ZINC='-include zconf.h' + ZINC='-I. -include zconf.h' ZINCOUT='-I. -I$(SRCDIR)' SRCDIR="$SRCDIR/" fi From 88ec24670e9c484219392def5f2f4b5e3f839db3 Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Sat, 20 Jan 2024 18:29:31 -0800 Subject: [PATCH 28/33] Remove -w compile option in configure test. Not all C compilers have a -w option. --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index 0b86d04e0..c55098afc 100755 --- a/configure +++ b/configure @@ -442,7 +442,7 @@ EOF if test $shared -eq 1; then echo Checking for shared library support... | tee -a configure.log # we must test in two steps (cc then ld), required at least on SunOS 4.x - if try $CC -w -c $SFLAGS $test.c && + if try $CC -c $SFLAGS $test.c && try $LDSHARED $SFLAGS -o $test$shared_ext $test.o; then echo Building shared library $SHAREDLIBV with $CC. | tee -a configure.log elif test -z "$old_cc" -a -z "$old_cflags"; then From c06dfecb8a0c996dce87148b9086f0fe79734f32 Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Sun, 21 Jan 2024 09:24:10 -0800 Subject: [PATCH 29/33] Use Makefile compiler for minizip-test target. --- Makefile.in | 2 +- contrib/minizip/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile.in b/Makefile.in index b584073b6..acda3b148 100644 --- a/Makefile.in +++ b/Makefile.in @@ -360,7 +360,7 @@ zconf: $(SRCDIR)zconf.h.in cp -p $(SRCDIR)zconf.h.in zconf.h minizip-test: static - cd contrib/minizip && { CFLAGS="$(CFLAGS)" $(MAKE) test ; cd ../.. ; } + cd contrib/minizip && { CC="$(CC)" CFLAGS="$(CFLAGS)" $(MAKE) test ; cd ../.. ; } minizip-clean: cd contrib/minizip && { $(MAKE) clean ; cd ../.. ; } diff --git a/contrib/minizip/Makefile b/contrib/minizip/Makefile index aac76e07f..3d927ec14 100644 --- a/contrib/minizip/Makefile +++ b/contrib/minizip/Makefile @@ -1,4 +1,4 @@ -CC=cc +CC?=cc CFLAGS := $(CFLAGS) -O -I../.. UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a From 2e3d86c4e12c4c23db4229eea7d0c1cd4571273e Mon Sep 17 00:00:00 2001 From: tr1cks Date: Mon, 26 Mar 2018 18:19:39 +0500 Subject: [PATCH 30/33] Add target include directories to CMakeLists.txt. This enables the addition of zlib to other projects. --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6fab3dcb1..c053a959b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -150,7 +150,9 @@ if(MINGW) endif(MINGW) add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) +target_include_directories(zlib PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) +target_include_directories(zlibstatic PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL) set_target_properties(zlib PROPERTIES SOVERSION 1) From 1a8db63788c34a50e39e273d39b7e1033208aea2 Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Mon, 22 Jan 2024 05:54:21 -0800 Subject: [PATCH 31/33] Move the load flags before the object files in Makefile tests. --- Makefile.in | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile.in b/Makefile.in index acda3b148..7200c96d1 100644 --- a/Makefile.in +++ b/Makefile.in @@ -22,7 +22,7 @@ CFLAGS=-O SFLAGS=-O LDFLAGS= -TEST_LDFLAGS=$(LDFLAGS) -L. libz.a +TEST_LIBS=-L. libz.a LDSHARED=$(CC) CPP=$(CC) -E @@ -282,10 +282,10 @@ placebo $(SHAREDLIBV): $(PIC_OBJS) libz.a -@rmdir objs example$(EXE): example.o $(STATICLIB) - $(CC) $(CFLAGS) -o $@ example.o $(TEST_LDFLAGS) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ example.o $(TEST_LIBS) minigzip$(EXE): minigzip.o $(STATICLIB) - $(CC) $(CFLAGS) -o $@ minigzip.o $(TEST_LDFLAGS) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ minigzip.o $(TEST_LIBS) examplesh$(EXE): example.o $(SHAREDLIBV) $(CC) $(CFLAGS) -o $@ example.o $(LDFLAGS) -L. $(SHAREDLIBV) @@ -294,10 +294,10 @@ minigzipsh$(EXE): minigzip.o $(SHAREDLIBV) $(CC) $(CFLAGS) -o $@ minigzip.o $(LDFLAGS) -L. $(SHAREDLIBV) example64$(EXE): example64.o $(STATICLIB) - $(CC) $(CFLAGS) -o $@ example64.o $(TEST_LDFLAGS) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ example64.o $(TEST_LIBS) minigzip64$(EXE): minigzip64.o $(STATICLIB) - $(CC) $(CFLAGS) -o $@ minigzip64.o $(TEST_LDFLAGS) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ minigzip64.o $(TEST_LIBS) install-libs: $(LIBS) -@if [ ! -d $(DESTDIR)$(exec_prefix) ]; then mkdir -p $(DESTDIR)$(exec_prefix); fi From 51b7f2abdade71cd9bb0e7a373ef2610ec6f9daf Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Mon, 22 Jan 2024 10:14:31 -0800 Subject: [PATCH 32/33] zlib 1.3.1 --- CMakeLists.txt | 2 +- ChangeLog | 11 +++++++++-- Makefile.in | 4 ++-- README | 6 +++--- contrib/delphi/ZLib.pas | 2 +- contrib/dotzlib/DotZLib/UnitTests.cs | 2 +- contrib/infback9/inftree9.c | 6 +++--- contrib/minizip/configure.ac | 2 +- contrib/nuget/nuget.csproj | 4 ++-- contrib/pascal/zlibpas.pas | 2 +- contrib/vstudio/readme.txt | 2 +- contrib/vstudio/vc10/zlib.rc | 8 ++++---- contrib/vstudio/vc10/zlibvc.def | 2 +- contrib/vstudio/vc11/zlib.rc | 8 ++++---- contrib/vstudio/vc11/zlibvc.def | 2 +- contrib/vstudio/vc12/zlib.rc | 8 ++++---- contrib/vstudio/vc12/zlibvc.def | 2 +- contrib/vstudio/vc14/zlib.rc | 8 ++++---- contrib/vstudio/vc14/zlibvc.def | 2 +- contrib/vstudio/vc17/zlib.rc | 8 ++++---- contrib/vstudio/vc17/zlibvc.def | 2 +- contrib/vstudio/vc9/zlib.rc | 8 ++++---- contrib/vstudio/vc9/zlibvc.def | 2 +- deflate.c | 4 ++-- deflate.h | 2 +- gzguts.h | 2 +- gzlib.c | 2 +- inftrees.c | 6 +++--- os400/README400 | 2 +- os400/zlib.inc | 8 ++++---- qnx/package.qpg | 10 +++++----- treebuild.xml | 4 ++-- trees.c | 2 +- win32/README-WIN32.txt | 4 ++-- zconf.h | 2 +- zconf.h.cmakein | 2 +- zconf.h.in | 2 +- zlib.3 | 6 +++--- zlib.3.pdf | Bin 19505 -> 25523 bytes zlib.h | 12 ++++++------ zutil.h | 2 +- 41 files changed, 91 insertions(+), 84 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c053a959b..15ceebe78 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON) project(zlib C) -set(VERSION "1.3.0.1") +set(VERSION "1.3.1") option(ZLIB_BUILD_EXAMPLES "Enable Zlib Examples" ON) diff --git a/ChangeLog b/ChangeLog index dfd652469..b801a1031 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,15 @@ ChangeLog file for zlib -Changes in 1.3.0.1 (xx Aug 2023) -- +Changes in 1.3.1 (22 Jan 2024) +- Reject overflows of zip header fields in minizip +- Fix bug in inflateSync() for data held in bit buffer +- Add LIT_MEM define to use more memory for a small deflate speedup +- Fix decision on the emission of Zip64 end records in minizip +- Add bounds checking to ERR_MSG() macro, used by zError() +- Neutralize zip file traversal attacks in miniunz +- Fix a bug in ZLIB_DEBUG compiles in check_match() +- Various portability and appearance improvements Changes in 1.3 (18 Aug 2023) - Remove K&R function definitions and zlib2ansi diff --git a/Makefile.in b/Makefile.in index 7200c96d1..cb8b00a9b 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,5 +1,5 @@ # Makefile for zlib -# Copyright (C) 1995-2017 Jean-loup Gailly, Mark Adler +# Copyright (C) 1995-2024 Jean-loup Gailly, Mark Adler # For conditions of distribution and use, see copyright notice in zlib.h # To compile and test, type: @@ -28,7 +28,7 @@ CPP=$(CC) -E STATICLIB=libz.a SHAREDLIB=libz.so -SHAREDLIBV=libz.so.1.3.0.1 +SHAREDLIBV=libz.so.1.3.1 SHAREDLIBM=libz.so.1 LIBS=$(STATICLIB) $(SHAREDLIBV) diff --git a/README b/README index 20f7064a5..c5f917540 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ ZLIB DATA COMPRESSION LIBRARY -zlib 1.3.0.1 is a general purpose data compression library. All the code is +zlib 1.3.1 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 (Request for Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950 (zlib format), rfc1951 (deflate format) and @@ -31,7 +31,7 @@ Mark Nelson wrote an article about zlib for the Jan. 1997 issue of Dr. Dobb's Journal; a copy of the article is available at https://marknelson.us/posts/1997/01/01/zlib-engine.html . -The changes made in version 1.3.0.1 are documented in the file ChangeLog. +The changes made in version 1.3.1 are documented in the file ChangeLog. Unsupported third party contributions are provided in directory contrib/ . @@ -83,7 +83,7 @@ Acknowledgments: Copyright notice: - (C) 1995-2023 Jean-loup Gailly and Mark Adler + (C) 1995-2024 Jean-loup Gailly and Mark Adler This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages diff --git a/contrib/delphi/ZLib.pas b/contrib/delphi/ZLib.pas index 814ffa670..93fa4c9ed 100644 --- a/contrib/delphi/ZLib.pas +++ b/contrib/delphi/ZLib.pas @@ -152,7 +152,7 @@ procedure DecompressToUserBuf(const InBuf: Pointer; InBytes: Integer; const OutBuf: Pointer; BufSize: Integer); const - zlib_version = '1.3.0'; + zlib_version = '1.3.1'; type EZlibError = class(Exception); diff --git a/contrib/dotzlib/DotZLib/UnitTests.cs b/contrib/dotzlib/DotZLib/UnitTests.cs index c5fce221a..d4f098023 100644 --- a/contrib/dotzlib/DotZLib/UnitTests.cs +++ b/contrib/dotzlib/DotZLib/UnitTests.cs @@ -156,7 +156,7 @@ public class InfoTests public void Info_Version() { Info info = new Info(); - Assert.AreEqual("1.3.0", Info.Version); + Assert.AreEqual("1.3.1", Info.Version); Assert.AreEqual(32, info.SizeOfUInt); Assert.AreEqual(32, info.SizeOfULong); Assert.AreEqual(32, info.SizeOfPointer); diff --git a/contrib/infback9/inftree9.c b/contrib/infback9/inftree9.c index 23f305010..ac707ed3f 100644 --- a/contrib/infback9/inftree9.c +++ b/contrib/infback9/inftree9.c @@ -1,5 +1,5 @@ /* inftree9.c -- generate Huffman trees for efficient decoding - * Copyright (C) 1995-2023 Mark Adler + * Copyright (C) 1995-2024 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -9,7 +9,7 @@ #define MAXBITS 15 const char inflate9_copyright[] = - " inflate9 1.3.0.1 Copyright 1995-2023 Mark Adler "; + " inflate9 1.3.1 Copyright 1995-2024 Mark Adler "; /* 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 @@ -59,7 +59,7 @@ int inflate_table9(codetype type, unsigned short FAR *lens, unsigned codes, static const unsigned short lext[31] = { /* Length codes 257..285 extra */ 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, 130, 130, 130, 130, 131, 131, 131, 131, 132, 132, 132, 132, - 133, 133, 133, 133, 144, 70, 200}; + 133, 133, 133, 133, 144, 203, 77}; static const unsigned short dbase[32] = { /* Distance codes 0..31 base */ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, diff --git a/contrib/minizip/configure.ac b/contrib/minizip/configure.ac index cdfee49cd..15ec91718 100644 --- a/contrib/minizip/configure.ac +++ b/contrib/minizip/configure.ac @@ -1,7 +1,7 @@ # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. -AC_INIT([minizip], [1.3.0.1], [bugzilla.redhat.com]) +AC_INIT([minizip], [1.3.1], [bugzilla.redhat.com]) AC_CONFIG_SRCDIR([minizip.c]) AM_INIT_AUTOMAKE([foreign]) LT_INIT diff --git a/contrib/nuget/nuget.csproj b/contrib/nuget/nuget.csproj index b72cbb67b..68627f034 100644 --- a/contrib/nuget/nuget.csproj +++ b/contrib/nuget/nuget.csproj @@ -6,8 +6,8 @@ $(PackageId).win $(PackageId).linux $(PackageId).osx - (C) 1995-2023 Jean-loup Gailly and Mark Adler - 1.3.0.1 + (C) 1995-2024 Jean-loup Gailly and Mark Adler + 1.3.1 NuGet Package for consuming native builds of zlib into .NET without complexity.