Skip to content

Commit 5715a30

Browse files
committed
Update zlib to 0f51fb4 @ https://github.com/madler/zlib
1 parent 9fe85c0 commit 5715a30

File tree

13 files changed

+208
-165
lines changed

13 files changed

+208
-165
lines changed

vendor/zlib/deflate.c

Lines changed: 46 additions & 20 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.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)
@@ -834,13 +846,13 @@ uLong ZEXPORT deflateBound(z_streamp strm, uLong sourceLen) {
834846
storelen = sourceLen + (sourceLen >> 5) + (sourceLen >> 7) +
835847
(sourceLen >> 11) + 7;
836848

837-
/* if can't get parameters, return larger bound plus a zlib wrapper */
849+
/* if can't get parameters, return larger bound plus a wrapper */
838850
if (deflateStateCheck(strm))
839-
return (fixedlen > storelen ? fixedlen : storelen) + 6;
851+
return (fixedlen > storelen ? fixedlen : storelen) + 18;
840852

841853
/* compute wrapper length */
842854
s = strm->state;
843-
switch (s->wrap) {
855+
switch (s->wrap < 0 ? -s->wrap : s->wrap) {
844856
case 0: /* raw deflate */
845857
wraplen = 0;
846858
break;
@@ -870,7 +882,7 @@ uLong ZEXPORT deflateBound(z_streamp strm, uLong sourceLen) {
870882
break;
871883
#endif
872884
default: /* for compiler happiness */
873-
wraplen = 6;
885+
wraplen = 18;
874886
}
875887

876888
/* if not default parameters, return one of the conservative bounds */
@@ -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) {
@@ -1610,7 +1635,8 @@ local block_state deflate_stored(deflate_state *s, int flush) {
16101635
* possible. If flushing, copy the remaining available input to next_out as
16111636
* stored blocks, if there is enough space.
16121637
*/
1613-
unsigned len, left, have, last = 0;
1638+
int last = 0;
1639+
unsigned len, left, have;
16141640
unsigned used = s->strm->avail_in;
16151641
do {
16161642
/* Set len to the maximum size block that we can copy directly with the
@@ -1646,10 +1672,10 @@ local block_state deflate_stored(deflate_state *s, int flush) {
16461672
_tr_stored_block(s, (char *)0, 0L, last);
16471673

16481674
/* Replace the lengths in the dummy stored block with len. */
1649-
s->pending_buf[s->pending - 4] = len;
1650-
s->pending_buf[s->pending - 3] = len >> 8;
1651-
s->pending_buf[s->pending - 2] = ~len;
1652-
s->pending_buf[s->pending - 1] = ~len >> 8;
1675+
s->pending_buf[s->pending - 4] = (Bytef)len;
1676+
s->pending_buf[s->pending - 3] = (Bytef)(len >> 8);
1677+
s->pending_buf[s->pending - 2] = (Bytef)~len;
1678+
s->pending_buf[s->pending - 1] = (Bytef)(~len >> 8);
16531679

16541680
/* Write the stored block header bytes. */
16551681
flush_pending(s->strm);

vendor/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) \

vendor/zlib/gzguts.h

Lines changed: 32 additions & 35 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

@@ -17,6 +17,18 @@
1717
# define ZLIB_INTERNAL
1818
#endif
1919

20+
#if defined(_WIN32)
21+
# ifndef WIN32_LEAN_AND_MEAN
22+
# define WIN32_LEAN_AND_MEAN
23+
# endif
24+
# ifndef _CRT_SECURE_NO_WARNINGS
25+
# define _CRT_SECURE_NO_WARNINGS
26+
# endif
27+
# ifndef _CRT_NONSTDC_NO_DEPRECATE
28+
# define _CRT_NONSTDC_NO_DEPRECATE
29+
# endif
30+
#endif
31+
2032
#include <stdio.h>
2133
#include "zlib.h"
2234
#ifdef STDC
@@ -25,8 +37,8 @@
2537
# include <limits.h>
2638
#endif
2739

28-
#ifndef _POSIX_SOURCE
29-
# define _POSIX_SOURCE
40+
#ifndef _POSIX_C_SOURCE
41+
# define _POSIX_C_SOURCE 200112L
3042
#endif
3143
#include <fcntl.h>
3244

@@ -36,19 +48,13 @@
3648

3749
#if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32)
3850
# include <io.h>
51+
# include <sys/stat.h>
3952
#endif
4053

41-
#if defined(_WIN32)
54+
#if defined(_WIN32) && !defined(WIDECHAR)
4255
# define WIDECHAR
4356
#endif
4457

45-
#ifdef WINAPI_FAMILY
46-
# define open _open
47-
# define read _read
48-
# define write _write
49-
# define close _close
50-
#endif
51-
5258
#ifdef NO_DEFLATE /* for compatibility with old definition */
5359
# define NO_GZCOMPRESS
5460
#endif
@@ -72,33 +78,28 @@
7278
#endif
7379

7480
#ifndef HAVE_VSNPRINTF
75-
# ifdef MSDOS
81+
# if !defined(NO_vsnprintf) && \
82+
(defined(MSDOS) || defined(__TURBOC__) || defined(__SASC) || \
83+
defined(VMS) || defined(__OS400) || defined(__MVS__))
7684
/* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
7785
but for now we just assume it doesn't. */
7886
# define NO_vsnprintf
7987
# endif
80-
# ifdef __TURBOC__
81-
# define NO_vsnprintf
82-
# endif
8388
# ifdef WIN32
8489
/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
85-
# if !defined(vsnprintf) && !defined(NO_vsnprintf)
86-
# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )
87-
# define vsnprintf _vsnprintf
90+
# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )
91+
# ifndef vsnprintf
92+
# define vsnprintf _vsnprintf
8893
# endif
8994
# endif
90-
# endif
91-
# ifdef __SASC
92-
# define NO_vsnprintf
93-
# endif
94-
# ifdef VMS
95-
# define NO_vsnprintf
96-
# endif
97-
# ifdef __OS400__
98-
# define NO_vsnprintf
99-
# endif
100-
# ifdef __MVS__
101-
# define NO_vsnprintf
95+
# elif !defined(__STDC_VERSION__) || __STDC_VERSION__-0 < 199901L
96+
/* Otherwise if C89/90, assume no C99 snprintf() or vsnprintf() */
97+
# ifndef NO_snprintf
98+
# define NO_snprintf
99+
# endif
100+
# ifndef NO_vsnprintf
101+
# define NO_vsnprintf
102+
# endif
102103
# endif
103104
#endif
104105

@@ -210,9 +211,5 @@ char ZLIB_INTERNAL *gz_strwinerror(DWORD error);
210211
/* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t
211212
value -- needed when comparing unsigned to z_off64_t, which is signed
212213
(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
216214
unsigned ZLIB_INTERNAL gz_intmax(void);
217-
# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())
218-
#endif
215+
#define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())

0 commit comments

Comments
 (0)