From 509d76f8212afa6f851932e09a00b36f6329555b Mon Sep 17 00:00:00 2001 From: Force Charlie Date: Sun, 31 Dec 2023 18:48:04 +0800 Subject: [PATCH] Sync zlib --- lib/archive/version.lock | 2 +- lib/archive/zlib/BUILD.gn | 3 +- lib/archive/zlib/README.chromium | 4 +- .../zlib/contrib/minizip/README.chromium | 1 + .../zlib/contrib/optimizations/inflate.c | 2 +- .../zlib/contrib/tests/utils_unittest.cc | 55 +++++++++++++++++++ lib/archive/zlib/crc32.c | 4 +- lib/archive/zlib/deflate.c | 38 ++++++++++++- lib/archive/zlib/deflate.h | 31 ++++++++++- lib/archive/zlib/google/compression_utils.cc | 22 ++++---- .../zlib/google/zip_reader_unittest.cc | 2 +- lib/archive/zlib/google/zip_unittest.cc | 4 +- lib/archive/zlib/gzguts.h | 5 +- lib/archive/zlib/gzlib.c | 4 +- lib/archive/zlib/inflate.c | 2 +- lib/archive/zlib/inftrees.c | 6 +- lib/archive/zlib/trees.c | 19 ++++++- lib/archive/zlib/zlib.3 | 4 +- lib/archive/zlib/zlib.h | 29 +++++----- 19 files changed, 187 insertions(+), 50 deletions(-) diff --git a/lib/archive/version.lock b/lib/archive/version.lock index 16cd6787..0315d490 100644 --- a/lib/archive/version.lock +++ b/lib/archive/version.lock @@ -1,4 +1,4 @@ brotli 1.1.0 liblzma: https://tukaani.org/xz/ 5.4.5 zstd: https://github.com/facebook/zstd/releases/download/v1.5.5/zstd-1.5.5.tar.gz#lib -zlib: https://github.com/chromium/chromium/tree/93c45e25631fd2b9a27d48b48b28958d3995ab5b/third_party/zlib \ No newline at end of file +zlib: https://github.com/chromium/chromium/tree/91a19f36beccbe06cb3fbb21312b8c25a7fd8991/third_party/zlib \ No newline at end of file diff --git a/lib/archive/zlib/BUILD.gn b/lib/archive/zlib/BUILD.gn index 8ed0807a..46627bca 100644 --- a/lib/archive/zlib/BUILD.gn +++ b/lib/archive/zlib/BUILD.gn @@ -3,6 +3,7 @@ # found in the LICENSE file. import("//build/config/compiler/compiler.gni") +import("//build/config/dcheck_always_on.gni") declare_args() { # Expose zlib's symbols, used by Node.js to provide zlib APIs for its native @@ -33,7 +34,7 @@ config("zlib_internal_config") { # Build code using -O3, see: crbug.com/1084371. configs = [ "//build/config/compiler:optimize_speed" ] } - if (is_debug || use_fuzzing_engine) { + if (is_debug || dcheck_always_on || use_fuzzing_engine) { # Enable zlib's asserts in debug and fuzzer builds. defines += [ "ZLIB_DEBUG" ] } diff --git a/lib/archive/zlib/README.chromium b/lib/archive/zlib/README.chromium index 1dfb9966..31b9d558 100644 --- a/lib/archive/zlib/README.chromium +++ b/lib/archive/zlib/README.chromium @@ -1,8 +1,8 @@ Name: zlib Short Name: zlib URL: http://zlib.net/ -Version: 1.2.13 -CPEPrefix: cpe:/a:zlib:zlib:1.2.13 +Version: 1.3.0.1 +CPEPrefix: cpe:/a:zlib:zlib:1.3.0.1 Security Critical: yes Shipped: yes License: Zlib diff --git a/lib/archive/zlib/contrib/minizip/README.chromium b/lib/archive/zlib/contrib/minizip/README.chromium index 9c780f94..b13de237 100644 --- a/lib/archive/zlib/contrib/minizip/README.chromium +++ b/lib/archive/zlib/contrib/minizip/README.chromium @@ -6,6 +6,7 @@ License: Zlib License File: //third_party/zlib/LICENSE Security Critical: yes Shipped: yes +CPEPrefix: cpe:/a:minizip_project:minizip Description: Minizip provides API on top of zlib that can enumerate and extract ZIP archive diff --git a/lib/archive/zlib/contrib/optimizations/inflate.c b/lib/archive/zlib/contrib/optimizations/inflate.c index 2a8e0ef7..c535c5af 100644 --- a/lib/archive/zlib/contrib/optimizations/inflate.c +++ b/lib/archive/zlib/contrib/optimizations/inflate.c @@ -1422,7 +1422,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) { diff --git a/lib/archive/zlib/contrib/tests/utils_unittest.cc b/lib/archive/zlib/contrib/tests/utils_unittest.cc index d06dbc98..4a802771 100644 --- a/lib/archive/zlib/contrib/tests/utils_unittest.cc +++ b/lib/archive/zlib/contrib/tests/utils_unittest.cc @@ -1025,6 +1025,61 @@ TEST(ZlibTest, DeflateZFixedCorruption) { 0); } +TEST(ZlibTest, DeflateCopy) { + // Check that deflateCopy() works. + + z_stream stream1; + stream1.zalloc = Z_NULL; + stream1.zfree = Z_NULL; + int ret = + deflateInit(&stream1, Z_DEFAULT_COMPRESSION); + ASSERT_EQ(ret, Z_OK); + std::vector compressed( + deflateBound(&stream1, strlen(zFixedCorruptionData))); + stream1.next_out = compressed.data(); + stream1.avail_out = compressed.size(); + + // Compress the first 1000 bytes. + stream1.next_in = (uint8_t*)zFixedCorruptionData; + stream1.avail_in = 1000; + ret = deflate(&stream1, Z_NO_FLUSH); + ASSERT_EQ(ret, Z_OK); + + // Copy the stream state. + z_stream stream2; + ret = deflateCopy(&stream2, &stream1); + ASSERT_EQ(ret, Z_OK); + deflateEnd(&stream1); + + // Compress the remaining bytes. + stream2.next_in = (uint8_t*)zFixedCorruptionData + (1000 - stream2.avail_in); + stream2.avail_in = strlen(zFixedCorruptionData) - (1000 - stream2.avail_in); + ret = deflate(&stream2, Z_FINISH); + ASSERT_EQ(ret, Z_STREAM_END); + size_t compressed_sz = compressed.size() - stream2.avail_out; + deflateEnd(&stream2); + + // Check that decompression is successful. + std::vector decompressed(strlen(zFixedCorruptionData)); + z_stream stream; + stream.zalloc = Z_NULL; + stream.zfree = Z_NULL; + ret = inflateInit(&stream); + ASSERT_EQ(ret, Z_OK); + stream.next_in = compressed.data(); + stream.avail_in = compressed_sz; + stream.next_out = decompressed.data(); + stream.avail_out = decompressed.size(); + ret = inflate(&stream, Z_FINISH); + ASSERT_EQ(ret, Z_STREAM_END); + inflateEnd(&stream); + + EXPECT_EQ(decompressed.size(), strlen(zFixedCorruptionData)); + EXPECT_EQ( + memcmp(zFixedCorruptionData, decompressed.data(), decompressed.size()), + 0); +} + // TODO(gustavoa): make these tests run standalone. #ifndef CMAKE_STANDALONE_UNITTESTS diff --git a/lib/archive/zlib/crc32.c b/lib/archive/zlib/crc32.c index 1e1a5751..cf8579f3 100644 --- a/lib/archive/zlib/crc32.c +++ b/lib/archive/zlib/crc32.c @@ -792,8 +792,8 @@ unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf, words = (z_word_t const *)buf; /* Do endian check at execution time instead of compile time, since ARM - processors can change the endianess at execution time. If the - compiler knows what the endianess will be, it can optimize out the + processors can change the endianness at execution time. If the + compiler knows what the endianness will be, it can optimize out the check and the unused branch. */ endian = 1; if (*(unsigned char *)&endian) { diff --git a/lib/archive/zlib/deflate.c b/lib/archive/zlib/deflate.c index 173ce596..4920e700 100644 --- a/lib/archive/zlib/deflate.c +++ b/lib/archive/zlib/deflate.c @@ -1,5 +1,5 @@ /* deflate.c -- compress data using the deflation algorithm - * Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler + * Copyright (C) 1995-2023 Jean-loup Gailly and Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -65,7 +65,7 @@ #endif const char deflate_copyright[] = - " deflate 1.2.13.1 Copyright 1995-2022 Jean-loup Gailly and Mark Adler "; + " deflate 1.3.0.1 Copyright 1995-2023 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 @@ -168,6 +168,11 @@ local const config configuration_table[10] = { * bit values at the expense of memory usage). We slide even when level == 0 to * keep the hash table consistent if we switch back to level > 0 later. */ +#if defined(__has_feature) +# if __has_feature(memory_sanitizer) + __attribute__((no_sanitize("memory"))) +# endif +#endif local void slide_hash(deflate_state *s) { #if defined(DEFLATE_SLIDE_HASH_SSE2) || defined(DEFLATE_SLIDE_HASH_NEON) slide_hash_simd(s->head, s->prev, s->w_size, s->hash_size); @@ -526,7 +531,11 @@ int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, * the compressed data for a dynamic block also cannot overwrite the * 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 || @@ -536,8 +545,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. @@ -749,9 +764,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) @@ -1324,7 +1345,11 @@ 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)); +#ifdef LIT_MEM + ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, 5); +#else ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, 4); +#endif if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL || ds->pending_buf == Z_NULL) { @@ -1335,10 +1360,19 @@ 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)); +#ifdef LIT_MEM + zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->lit_bufsize * 5); +#else zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size); +#endif 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/lib/archive/zlib/deflate.h b/lib/archive/zlib/deflate.h index f1641911..eb7f0724 100644 --- a/lib/archive/zlib/deflate.h +++ b/lib/archive/zlib/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 */ @@ -323,6 +332,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; \ @@ -342,6 +370,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/lib/archive/zlib/google/compression_utils.cc b/lib/archive/zlib/google/compression_utils.cc index 279ea073..c2b17e4c 100644 --- a/lib/archive/zlib/google/compression_utils.cc +++ b/lib/archive/zlib/google/compression_utils.cc @@ -4,7 +4,6 @@ #include "third_party/zlib/google/compression_utils.h" -#include "base/bit_cast.h" #include "base/check_op.h" #include "base/process/memory.h" #include "base/sys_byteorder.h" @@ -24,8 +23,8 @@ bool GzipCompress(base::span input, // uLongf can be larger than size_t. uLongf compressed_size_long = static_cast(output_buffer_size); if (zlib_internal::GzipCompressHelper( - base::bit_cast(output_buffer), &compressed_size_long, - base::bit_cast(input.data()), + reinterpret_cast(output_buffer), &compressed_size_long, + reinterpret_cast(input.data()), static_cast(input.size()), malloc_fn, free_fn) != Z_OK) { return false; } @@ -55,7 +54,7 @@ bool GzipCompress(base::span input, std::string* output) { if (zlib_internal::GzipCompressHelper( compressed_data, &compressed_data_size, - base::bit_cast(input.data()), input_size, nullptr, + reinterpret_cast(input.data()), input_size, nullptr, nullptr) != Z_OK) { free(compressed_data); return false; @@ -82,8 +81,8 @@ bool GzipUncompress(const std::string& input, std::string* output) { uncompressed_output.resize(uncompressed_size); if (zlib_internal::GzipUncompressHelper( - base::bit_cast(uncompressed_output.data()), - &uncompressed_size, base::bit_cast(input.data()), + reinterpret_cast(uncompressed_output.data()), + &uncompressed_size, reinterpret_cast(input.data()), static_cast(input.length())) == Z_OK) { output->swap(uncompressed_output); return true; @@ -102,8 +101,8 @@ bool GzipUncompress(base::span input, if (uncompressed_size > output.size()) return false; return zlib_internal::GzipUncompressHelper( - base::bit_cast(output.data()), &uncompressed_size, - base::bit_cast(input.data()), + reinterpret_cast(const_cast(output.data())), + &uncompressed_size, reinterpret_cast(input.data()), static_cast(input.size())) == Z_OK; } @@ -117,8 +116,8 @@ bool GzipUncompress(base::span input, std::string* output) { uLongf uncompressed_size = GetUncompressedSize(input); output->resize(uncompressed_size); return zlib_internal::GzipUncompressHelper( - base::bit_cast(output->data()), &uncompressed_size, - base::bit_cast(input.data()), + reinterpret_cast(output->data()), &uncompressed_size, + reinterpret_cast(input.data()), static_cast(input.size())) == Z_OK; } @@ -128,7 +127,8 @@ uint32_t GetUncompressedSize(base::span compressed_data) { uint32_t GetUncompressedSize(base::span compressed_data) { return zlib_internal::GetGzipUncompressedSize( - base::bit_cast(compressed_data.data()), compressed_data.size()); + reinterpret_cast(compressed_data.data()), + compressed_data.size()); } } // namespace compression diff --git a/lib/archive/zlib/google/zip_reader_unittest.cc b/lib/archive/zlib/google/zip_reader_unittest.cc index 6086c97c..8ef0274e 100644 --- a/lib/archive/zlib/google/zip_reader_unittest.cc +++ b/lib/archive/zlib/google/zip_reader_unittest.cc @@ -157,7 +157,7 @@ class ZipReaderTest : public PlatformTest { static base::FilePath GetTestDataDirectory() { base::FilePath path; - CHECK(base::PathService::Get(base::DIR_SOURCE_ROOT, &path)); + CHECK(base::PathService::Get(base::DIR_SRC_TEST_DATA_ROOT, &path)); return path.AppendASCII("third_party") .AppendASCII("zlib") .AppendASCII("google") diff --git a/lib/archive/zlib/google/zip_unittest.cc b/lib/archive/zlib/google/zip_unittest.cc index d0fc02fd..922d3830 100644 --- a/lib/archive/zlib/google/zip_unittest.cc +++ b/lib/archive/zlib/google/zip_unittest.cc @@ -206,7 +206,7 @@ class VirtualFileSystem : public zip::FileAccessor { info->is_directory = !files_.count(path); info->last_modified = - base::Time::FromDoubleT(172097977); // Some random date. + base::Time::FromSecondsSinceUnixEpoch(172097977); // Some random date. return true; } @@ -256,7 +256,7 @@ class ZipTest : public PlatformTest { static base::FilePath GetDataDirectory() { base::FilePath path; - bool success = base::PathService::Get(base::DIR_SOURCE_ROOT, &path); + bool success = base::PathService::Get(base::DIR_SRC_TEST_DATA_ROOT, &path); EXPECT_TRUE(success); return std::move(path) .AppendASCII("third_party") diff --git a/lib/archive/zlib/gzguts.h b/lib/archive/zlib/gzguts.h index e23f831f..f9375047 100644 --- a/lib/archive/zlib/gzguts.h +++ b/lib/archive/zlib/gzguts.h @@ -7,9 +7,8 @@ # ifndef _LARGEFILE_SOURCE # define _LARGEFILE_SOURCE 1 # endif -# ifdef _FILE_OFFSET_BITS -# undef _FILE_OFFSET_BITS -# endif +# undef _FILE_OFFSET_BITS +# undef _TIME_BITS #endif #ifdef HAVE_HIDDEN diff --git a/lib/archive/zlib/gzlib.c b/lib/archive/zlib/gzlib.c index 9810e355..0d3ebf8d 100644 --- a/lib/archive/zlib/gzlib.c +++ b/lib/archive/zlib/gzlib.c @@ -311,8 +311,8 @@ int ZEXPORT gzbuffer(gzFile file, unsigned size) { /* check and set requested size */ if ((size << 1) < size) return -1; /* need to be able to double it */ - if (size < 2) - size = 2; /* need two bytes to check magic header */ + if (size < 8) + size = 8; /* needed to behave well with flushing */ state->want = size; return 0; } diff --git a/lib/archive/zlib/inflate.c b/lib/archive/zlib/inflate.c index 5abbd074..0990ae7b 100644 --- a/lib/archive/zlib/inflate.c +++ b/lib/archive/zlib/inflate.c @@ -1389,7 +1389,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) { diff --git a/lib/archive/zlib/inftrees.c b/lib/archive/zlib/inftrees.c index afc4c421..73d5a776 100644 --- a/lib/archive/zlib/inftrees.c +++ b/lib/archive/zlib/inftrees.c @@ -1,5 +1,5 @@ /* inftrees.c -- generate Huffman trees for efficient decoding - * Copyright (C) 1995-2022 Mark Adler + * Copyright (C) 1995-2023 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -9,7 +9,7 @@ #define MAXBITS 15 const char inflate_copyright[] = - " inflate 1.2.13.1 Copyright 1995-2022 Mark Adler "; + " inflate 1.3.0.1 Copyright 1995-2023 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 @@ -57,7 +57,7 @@ int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; static const unsigned short lext[31] = { /* Length codes 257..285 extra */ 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, - 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 77, 76}; + 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 70, 200}; static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, diff --git a/lib/archive/zlib/trees.c b/lib/archive/zlib/trees.c index 8dbdc40b..38135273 100644 --- a/lib/archive/zlib/trees.c +++ b/lib/archive/zlib/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,13 @@ 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 << 1), + "pendingBuf overflow"); +#else Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow"); +#endif } while (sx < s->sym_next); @@ -1082,9 +1092,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++; diff --git a/lib/archive/zlib/zlib.3 b/lib/archive/zlib/zlib.3 index e733b5ab..adc5b7f0 100644 --- a/lib/archive/zlib/zlib.3 +++ b/lib/archive/zlib/zlib.3 @@ -1,4 +1,4 @@ -.TH ZLIB 3 "xx Oct 2022" +.TH ZLIB 3 "xx Aug 2023" .SH NAME zlib \- compression/decompression library .SH SYNOPSIS @@ -105,7 +105,7 @@ before asking for help. Send questions and/or comments to zlib@gzip.org, or (for the Windows DLL version) to Gilles Vollant (info@winimage.com). .SH AUTHORS AND LICENSE -Version 1.2.13.1 +Version 1.2.3.0.1 .LP Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler .LP diff --git a/lib/archive/zlib/zlib.h b/lib/archive/zlib/zlib.h index 014331fc..f1b149b9 100644 --- a/lib/archive/zlib/zlib.h +++ b/lib/archive/zlib/zlib.h @@ -1,7 +1,7 @@ /* zlib.h -- interface of the 'zlib' general purpose compression library - version 1.2.13.1, October xxth, 2022 + version 1.3.0.1, August xxth, 2023 - Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler + Copyright (C) 1995-2023 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 @@ -37,11 +37,11 @@ extern "C" { #endif -#define ZLIB_VERSION "1.2.13.1-motley" -#define ZLIB_VERNUM 0x12d1 +#define ZLIB_VERSION "1.3.0.1-motley" +#define ZLIB_VERNUM 0x1301 #define ZLIB_VER_MAJOR 1 -#define ZLIB_VER_MINOR 2 -#define ZLIB_VER_REVISION 13 +#define ZLIB_VER_MINOR 3 +#define ZLIB_VER_REVISION 0 #define ZLIB_VER_SUBREVISION 1 /* @@ -230,7 +230,7 @@ ZEXTERN int ZEXPORT deflateInit(z_streamp strm, int level); Initializes the internal stream state for compression. The fields zalloc, zfree and opaque must be initialized before by the caller. If zalloc and zfree are set to Z_NULL, deflateInit updates them to use default - allocation functions. + allocation functions. total_in, total_out, adler, and msg are initialized. The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: 1 gives best speed, 9 gives best compression, 0 gives no compression at all @@ -320,8 +320,8 @@ ZEXTERN int ZEXPORT deflate(z_streamp strm, int flush); with the same value of the flush parameter and more output space (updated avail_out), until the flush is complete (deflate returns with non-zero avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that - avail_out is greater than six to avoid repeated flush markers due to - avail_out == 0 on return. + avail_out is greater than six when the flush marker begins, in order to avoid + repeated flush markers upon calling deflate() again when avail_out == 0. If the parameter flush is set to Z_FINISH, pending input is processed, pending output is flushed and deflate returns with Z_STREAM_END if there was @@ -382,7 +382,8 @@ ZEXTERN int ZEXPORT inflateInit(z_streamp strm); read or consumed. The allocation of a sliding window will be deferred to the first call of inflate (if the decompression does not complete on the first call). If zalloc and zfree are set to Z_NULL, inflateInit updates - them to use default allocation functions. + them to use default allocation functions. total_in, total_out, adler, and + msg are initialized. inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough memory, Z_VERSION_ERROR if the zlib library version is incompatible with the @@ -695,7 +696,7 @@ ZEXTERN int ZEXPORT deflateReset(z_streamp strm); This function is equivalent to deflateEnd followed by deflateInit, but does not free and reallocate the internal compression state. The stream will leave the compression level and any other attributes that may have been - set unchanged. + set unchanged. total_in, total_out, adler, and msg are initialized. deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source stream state was inconsistent (such as zalloc or state being Z_NULL). @@ -820,8 +821,9 @@ ZEXTERN int ZEXPORT deflateSetHeader(z_streamp strm, gzip file" and give up. If deflateSetHeader is not used, the default gzip header has text false, - the time set to zero, and os set to 255, with no extra, name, or comment - fields. The gzip header is returned to the default state by deflateReset(). + the time set to zero, and os set to the current operating system, with no + extra, name, or comment fields. The gzip header is returned to the default + state by deflateReset(). deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source stream state was inconsistent. @@ -960,6 +962,7 @@ ZEXTERN int ZEXPORT inflateReset(z_streamp strm); This function is equivalent to inflateEnd followed by inflateInit, but does not free and reallocate the internal decompression state. The stream will keep attributes that may have been set by inflateInit2. + total_in, total_out, adler, and msg are initialized. inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source stream state was inconsistent (such as zalloc or state being Z_NULL).