|
@@ -1,5 +1,5 @@
|
|
|
/* deflate.c -- compress data using the deflation algorithm
|
|
|
- * Copyright (C) 1995-2023 Jean-loup Gailly and Mark Adler
|
|
|
+ * Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler
|
|
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
|
|
*/
|
|
|
|
|
@@ -53,7 +53,7 @@
|
|
|
#include <util/system/compiler.h>
|
|
|
|
|
|
const char deflate_copyright[] =
|
|
|
- " deflate 1.3 Copyright 1995-2023 Jean-loup Gailly and Mark Adler ";
|
|
|
+ " deflate 1.3.1 Copyright 1995-2024 Jean-loup Gailly and 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
|
|
@@ -496,7 +496,7 @@ int ZEXPORT deflateInit2_(z_streamp strm, int level, int method,
|
|
|
* symbols from which it is being constructed.
|
|
|
*/
|
|
|
|
|
|
- s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, 4);
|
|
|
+ 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 ||
|
|
@@ -506,8 +506,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.
|
|
@@ -723,9 +729,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)
|
|
@@ -1297,7 +1309,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) {
|
|
@@ -1308,10 +1320,15 @@ 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
|
|
|
+ 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;
|
|
@@ -1543,13 +1560,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) {
|