Skip to content

Commit 187b4cf

Browse files
ShaurenThelsen
authored andcommitted
Dep/zlib: Update to 1.3.1
(cherry picked from commit 93cc4f98f52a8abfd9adb36e660fe84dd1b54383)
1 parent 55cc4a0 commit 187b4cf

14 files changed

Lines changed: 149 additions & 79 deletions

File tree

dep/PackageList.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ utf8-cpp (UTF-8 with C++ in a Portable Way)
5050

5151
zlib (A Massively Spiffy Yet Delicately Unobtrusive Compression Library)
5252
http://www.zlib.net/
53-
Version: 1.3
53+
Version: 1.3.1
5454

5555
gSOAP (a portable development toolkit for C and C++ XML Web services and XML data bindings)
5656
http://gsoap2.sourceforge.net/

dep/zlib/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,25 @@ else()
2626
adler32.c
2727
compress.c
2828
crc32.c
29+
crc32.h
2930
deflate.c
31+
deflate.h
32+
gzguts.h
3033
infback.c
3134
inffast.c
35+
inffast.h
36+
inffixed.h
3237
inflate.c
38+
inflate.h
3339
inftrees.c
40+
inftrees.h
3441
trees.c
42+
trees.h
3543
uncompr.c
44+
zconf.h
45+
zlib.h
3646
zutil.c
47+
zutil.h
3748
)
3849

3950
add_library(zlib STATIC

dep/zlib/LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright notice:
2+
3+
(C) 1995-2022 Jean-loup Gailly and Mark Adler
4+
5+
This software is provided 'as-is', without any express or implied
6+
warranty. In no event will the authors be held liable for any damages
7+
arising from the use of this software.
8+
9+
Permission is granted to anyone to use this software for any purpose,
10+
including commercial applications, and to alter it and redistribute it
11+
freely, subject to the following restrictions:
12+
13+
1. The origin of this software must not be misrepresented; you must not
14+
claim that you wrote the original software. If you use this software
15+
in a product, an acknowledgment in the product documentation would be
16+
appreciated but is not required.
17+
2. Altered source versions must be plainly marked as such, and must not be
18+
misrepresented as being the original software.
19+
3. This notice may not be removed or altered from any source distribution.
20+
21+
Jean-loup Gailly Mark Adler
22+
jloup@gzip.org madler@alumni.caltech.edu

dep/zlib/deflate.c

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* deflate.c -- compress data using the deflation algorithm
2-
* Copyright (C) 1995-2023 Jean-loup Gailly and Mark Adler
2+
* Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler
33
* For conditions of distribution and use, see copyright notice in zlib.h
44
*/
55

@@ -52,7 +52,7 @@
5252
#include "deflate.h"
5353

5454
const char deflate_copyright[] =
55-
" deflate 1.3 Copyright 1995-2023 Jean-loup Gailly and Mark Adler ";
55+
" deflate 1.3.1 Copyright 1995-2024 Jean-loup Gailly and Mark Adler ";
5656
/*
5757
If you use the zlib library in a product, an acknowledgment is welcome
5858
in the documentation of your product. If for some reason you cannot
@@ -493,7 +493,7 @@ int ZEXPORT deflateInit2_(z_streamp strm, int level, int method,
493493
* symbols from which it is being constructed.
494494
*/
495495

496-
s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, 4);
496+
s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, LIT_BUFS);
497497
s->pending_buf_size = (ulg)s->lit_bufsize * 4;
498498

499499
if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
@@ -503,8 +503,14 @@ int ZEXPORT deflateInit2_(z_streamp strm, int level, int method,
503503
deflateEnd (strm);
504504
return Z_MEM_ERROR;
505505
}
506+
#ifdef LIT_MEM
507+
s->d_buf = (ushf *)(s->pending_buf + (s->lit_bufsize << 1));
508+
s->l_buf = s->pending_buf + (s->lit_bufsize << 2);
509+
s->sym_end = s->lit_bufsize - 1;
510+
#else
506511
s->sym_buf = s->pending_buf + s->lit_bufsize;
507512
s->sym_end = (s->lit_bufsize - 1) * 3;
513+
#endif
508514
/* We avoid equality with lit_bufsize*3 because of wraparound at 64K
509515
* on 16 bit machines and because stored blocks are restricted to
510516
* 64K-1 bytes.
@@ -720,9 +726,15 @@ int ZEXPORT deflatePrime(z_streamp strm, int bits, int value) {
720726

721727
if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
722728
s = strm->state;
729+
#ifdef LIT_MEM
730+
if (bits < 0 || bits > 16 ||
731+
(uchf *)s->d_buf < s->pending_out + ((Buf_size + 7) >> 3))
732+
return Z_BUF_ERROR;
733+
#else
723734
if (bits < 0 || bits > 16 ||
724735
s->sym_buf < s->pending_out + ((Buf_size + 7) >> 3))
725736
return Z_BUF_ERROR;
737+
#endif
726738
do {
727739
put = Buf_size - s->bi_valid;
728740
if (put > bits)
@@ -1294,7 +1306,7 @@ int ZEXPORT deflateCopy(z_streamp dest, z_streamp source) {
12941306
ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
12951307
ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
12961308
ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
1297-
ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, 4);
1309+
ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, LIT_BUFS);
12981310

12991311
if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
13001312
ds->pending_buf == Z_NULL) {
@@ -1305,10 +1317,15 @@ int ZEXPORT deflateCopy(z_streamp dest, z_streamp source) {
13051317
zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
13061318
zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos));
13071319
zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos));
1308-
zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
1320+
zmemcpy(ds->pending_buf, ss->pending_buf, ds->lit_bufsize * LIT_BUFS);
13091321

13101322
ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
1323+
#ifdef LIT_MEM
1324+
ds->d_buf = (ushf *)(ds->pending_buf + (ds->lit_bufsize << 1));
1325+
ds->l_buf = ds->pending_buf + (ds->lit_bufsize << 2);
1326+
#else
13111327
ds->sym_buf = ds->pending_buf + ds->lit_bufsize;
1328+
#endif
13121329

13131330
ds->l_desc.dyn_tree = ds->dyn_ltree;
13141331
ds->d_desc.dyn_tree = ds->dyn_dtree;
@@ -1539,13 +1556,21 @@ local uInt longest_match(deflate_state *s, IPos cur_match) {
15391556
*/
15401557
local void check_match(deflate_state *s, IPos start, IPos match, int length) {
15411558
/* check that the match is indeed a match */
1542-
if (zmemcmp(s->window + match,
1543-
s->window + start, length) != EQUAL) {
1544-
fprintf(stderr, " start %u, match %u, length %d\n",
1545-
start, match, length);
1559+
Bytef *back = s->window + (int)match, *here = s->window + start;
1560+
IPos len = length;
1561+
if (match == (IPos)-1) {
1562+
/* match starts one byte before the current window -- just compare the
1563+
subsequent length-1 bytes */
1564+
back++;
1565+
here++;
1566+
len--;
1567+
}
1568+
if (zmemcmp(back, here, len) != EQUAL) {
1569+
fprintf(stderr, " start %u, match %d, length %d\n",
1570+
start, (int)match, length);
15461571
do {
1547-
fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
1548-
} while (--length != 0);
1572+
fprintf(stderr, "(%02x %02x)", *back++, *here++);
1573+
} while (--len != 0);
15491574
z_error("invalid match");
15501575
}
15511576
if (z_verbose > 1) {

dep/zlib/deflate.h

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* deflate.h -- internal compression state
2-
* Copyright (C) 1995-2018 Jean-loup Gailly
2+
* Copyright (C) 1995-2024 Jean-loup Gailly
33
* For conditions of distribution and use, see copyright notice in zlib.h
44
*/
55

@@ -23,6 +23,10 @@
2323
# define GZIP
2424
#endif
2525

26+
/* define LIT_MEM to slightly increase the speed of deflate (order 1% to 2%) at
27+
the cost of a larger memory footprint */
28+
/* #define LIT_MEM */
29+
2630
/* ===========================================================================
2731
* Internal compression state.
2832
*/
@@ -217,7 +221,14 @@ typedef struct internal_state {
217221
/* Depth of each subtree used as tie breaker for trees of equal frequency
218222
*/
219223

224+
#ifdef LIT_MEM
225+
# define LIT_BUFS 5
226+
ushf *d_buf; /* buffer for distances */
227+
uchf *l_buf; /* buffer for literals/lengths */
228+
#else
229+
# define LIT_BUFS 4
220230
uchf *sym_buf; /* buffer for distances and literals/lengths */
231+
#endif
221232

222233
uInt lit_bufsize;
223234
/* Size of match buffer for literals/lengths. There are 4 reasons for
@@ -239,7 +250,7 @@ typedef struct internal_state {
239250
* - I can't count above 4
240251
*/
241252

242-
uInt sym_next; /* running index in sym_buf */
253+
uInt sym_next; /* running index in symbol buffer */
243254
uInt sym_end; /* symbol table full when sym_next reaches this */
244255

245256
ulg opt_len; /* bit length of current block with optimal trees */
@@ -318,6 +329,25 @@ void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf,
318329
extern const uch ZLIB_INTERNAL _dist_code[];
319330
#endif
320331

332+
#ifdef LIT_MEM
333+
# define _tr_tally_lit(s, c, flush) \
334+
{ uch cc = (c); \
335+
s->d_buf[s->sym_next] = 0; \
336+
s->l_buf[s->sym_next++] = cc; \
337+
s->dyn_ltree[cc].Freq++; \
338+
flush = (s->sym_next == s->sym_end); \
339+
}
340+
# define _tr_tally_dist(s, distance, length, flush) \
341+
{ uch len = (uch)(length); \
342+
ush dist = (ush)(distance); \
343+
s->d_buf[s->sym_next] = dist; \
344+
s->l_buf[s->sym_next++] = len; \
345+
dist--; \
346+
s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
347+
s->dyn_dtree[d_code(dist)].Freq++; \
348+
flush = (s->sym_next == s->sym_end); \
349+
}
350+
#else
321351
# define _tr_tally_lit(s, c, flush) \
322352
{ uch cc = (c); \
323353
s->sym_buf[s->sym_next++] = 0; \
@@ -337,6 +367,7 @@ void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf,
337367
s->dyn_dtree[d_code(dist)].Freq++; \
338368
flush = (s->sym_next == s->sym_end); \
339369
}
370+
#endif
340371
#else
341372
# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
342373
# define _tr_tally_dist(s, distance, length, flush) \

dep/zlib/gzguts.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* gzguts.h -- zlib internal header definitions for gz* operations
2-
* Copyright (C) 2004-2019 Mark Adler
2+
* Copyright (C) 2004-2024 Mark Adler
33
* For conditions of distribution and use, see copyright notice in zlib.h
44
*/
55

@@ -210,9 +210,5 @@ char ZLIB_INTERNAL *gz_strwinerror(DWORD error);
210210
/* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t
211211
value -- needed when comparing unsigned to z_off64_t, which is signed
212212
(possible z_off64_t types off_t, off64_t, and long are all signed) */
213-
#ifdef INT_MAX
214-
# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX)
215-
#else
216213
unsigned ZLIB_INTERNAL gz_intmax(void);
217-
# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())
218-
#endif
214+
#define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())

dep/zlib/gzlib.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* gzlib.c -- zlib functions common to reading and writing gzip files
2-
* Copyright (C) 2004-2019 Mark Adler
2+
* Copyright (C) 2004-2024 Mark Adler
33
* For conditions of distribution and use, see copyright notice in zlib.h
44
*/
55

@@ -563,20 +563,20 @@ void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg) {
563563
#endif
564564
}
565565

566-
#ifndef INT_MAX
567566
/* portably return maximum value for an int (when limits.h presumed not
568567
available) -- we need to do this to cover cases where 2's complement not
569568
used, since C standard permits 1's complement and sign-bit representations,
570569
otherwise we could just use ((unsigned)-1) >> 1 */
571570
unsigned ZLIB_INTERNAL gz_intmax(void) {
572-
unsigned p, q;
573-
574-
p = 1;
571+
#ifdef INT_MAX
572+
return INT_MAX;
573+
#else
574+
unsigned p = 1, q;
575575
do {
576576
q = p;
577577
p <<= 1;
578578
p++;
579579
} while (p > q);
580580
return q >> 1;
581-
}
582581
#endif
582+
}

dep/zlib/inflate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1387,7 +1387,7 @@ int ZEXPORT inflateSync(z_streamp strm) {
13871387
/* if first time, start search in bit buffer */
13881388
if (state->mode != SYNC) {
13891389
state->mode = SYNC;
1390-
state->hold <<= state->bits & 7;
1390+
state->hold >>= state->bits & 7;
13911391
state->bits -= state->bits & 7;
13921392
len = 0;
13931393
while (state->bits >= 8) {

dep/zlib/inftrees.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* inftrees.c -- generate Huffman trees for efficient decoding
2-
* Copyright (C) 1995-2023 Mark Adler
2+
* Copyright (C) 1995-2024 Mark Adler
33
* For conditions of distribution and use, see copyright notice in zlib.h
44
*/
55

@@ -9,7 +9,7 @@
99
#define MAXBITS 15
1010

1111
const char inflate_copyright[] =
12-
" inflate 1.3 Copyright 1995-2023 Mark Adler ";
12+
" inflate 1.3.1 Copyright 1995-2024 Mark Adler ";
1313
/*
1414
If you use the zlib library in a product, an acknowledgment is welcome
1515
in the documentation of your product. If for some reason you cannot
@@ -57,7 +57,7 @@ int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
5757
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
5858
static const unsigned short lext[31] = { /* Length codes 257..285 extra */
5959
16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
60-
19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 198, 203};
60+
19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 203, 77};
6161
static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
6262
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
6363
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,

dep/zlib/inftrees.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ typedef struct {
4141
examples/enough.c found in the zlib distribution. The arguments to that
4242
program are the number of symbols, the initial root table size, and the
4343
maximum bit length of a code. "enough 286 9 15" for literal/length codes
44-
returns returns 852, and "enough 30 6 15" for distance codes returns 592.
45-
The initial root table size (9 or 6) is found in the fifth argument of the
44+
returns 852, and "enough 30 6 15" for distance codes returns 592. The
45+
initial root table size (9 or 6) is found in the fifth argument of the
4646
inflate_table() calls in inflate.c and infback.c. If the root table size is
4747
changed, then these maximum sizes would be need to be recalculated and
4848
updated. */

0 commit comments

Comments
 (0)