From a41dca0c51e1bb4dbe9bf83146a919dada3b663f Mon Sep 17 00:00:00 2001 From: "Node.js GitHub Bot" Date: Tue, 26 Dec 2023 02:30:05 +0200 Subject: [PATCH] deps: update zlib to 1.3.0.1-motley-40e35a7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/51274 Reviewed-By: Luigi Pinca Reviewed-By: Michaƫl Zasso --- deps/zlib/BUILD.gn | 3 +- deps/zlib/contrib/tests/utils_unittest.cc | 55 +++++++++++++++++++++++ deps/zlib/deflate.c | 8 ++++ deps/zlib/deflate.h | 2 +- deps/zlib/google/compression_utils.cc | 22 ++++----- deps/zlib/trees.c | 3 +- src/zlib_version.h | 2 +- 7 files changed, 80 insertions(+), 15 deletions(-) diff --git a/deps/zlib/BUILD.gn b/deps/zlib/BUILD.gn index 8ed0807a994b1e..46627bca7eb158 100644 --- a/deps/zlib/BUILD.gn +++ b/deps/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/deps/zlib/contrib/tests/utils_unittest.cc b/deps/zlib/contrib/tests/utils_unittest.cc index d06dbc9812ad92..4a8027717920f6 100644 --- a/deps/zlib/contrib/tests/utils_unittest.cc +++ b/deps/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/deps/zlib/deflate.c b/deps/zlib/deflate.c index adb2488224516a..4920e7007af887 100644 --- a/deps/zlib/deflate.c +++ b/deps/zlib/deflate.c @@ -1345,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) { @@ -1356,7 +1360,11 @@ 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 diff --git a/deps/zlib/deflate.h b/deps/zlib/deflate.h index 654d0944cda29a..eb7f0724015cc7 100644 --- a/deps/zlib/deflate.h +++ b/deps/zlib/deflate.h @@ -25,7 +25,7 @@ /* 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 */ +#define LIT_MEM /* =========================================================================== * Internal compression state. diff --git a/deps/zlib/google/compression_utils.cc b/deps/zlib/google/compression_utils.cc index 279ea0732980c3..c2b17e4ced6f22 100644 --- a/deps/zlib/google/compression_utils.cc +++ b/deps/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/deps/zlib/trees.c b/deps/zlib/trees.c index 5ca23e9381a3a3..38135273c9c3bc 100644 --- a/deps/zlib/trees.c +++ b/deps/zlib/trees.c @@ -938,7 +938,8 @@ 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 < (s->lit_bufsize << 1) + (sx << 1), + "pendingBuf overflow"); #else Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow"); #endif diff --git a/src/zlib_version.h b/src/zlib_version.h index b15d94fdfbe88d..10aa3283c81aab 100644 --- a/src/zlib_version.h +++ b/src/zlib_version.h @@ -2,5 +2,5 @@ // Refer to tools/dep_updaters/update-zlib.sh #ifndef SRC_ZLIB_VERSION_H_ #define SRC_ZLIB_VERSION_H_ -#define ZLIB_VERSION "1.3.0.1-motley-dd5fc13" +#define ZLIB_VERSION "1.3.0.1-motley-40e35a7" #endif // SRC_ZLIB_VERSION_H_