From e7db63972c9d3597a07a84138d446ad76424e1c6 Mon Sep 17 00:00:00 2001 From: "Node.js GitHub Bot" Date: Sun, 7 Jul 2024 00:28:55 +0000 Subject: [PATCH] deps: update zlib to 1.3.0.1-motley-68e57e6 PR-URL: https://github.com/nodejs/node/pull/53464 Reviewed-By: Chemi Atlow Reviewed-By: Marco Ippolito Reviewed-By: Rafael Gonzaga Reviewed-By: James M Snell --- deps/zlib/contrib/bench/zlib_bench.cc | 20 +++----- deps/zlib/contrib/tests/fuzzers/BUILD.gn | 5 ++ .../contrib/tests/fuzzers/compress_fuzzer.cc | 46 +++++++++++++++++++ src/zlib_version.h | 2 +- 4 files changed, 58 insertions(+), 15 deletions(-) create mode 100644 deps/zlib/contrib/tests/fuzzers/compress_fuzzer.cc diff --git a/deps/zlib/contrib/bench/zlib_bench.cc b/deps/zlib/contrib/bench/zlib_bench.cc index b65f9291bff500..6df296c8721056 100644 --- a/deps/zlib/contrib/bench/zlib_bench.cc +++ b/deps/zlib/contrib/bench/zlib_bench.cc @@ -71,10 +71,6 @@ Data read_file_data_or_exit(const char* name) { return data; } -size_t zlib_estimate_compressed_size(size_t input_size) { - return compressBound(input_size); -} - enum zlib_wrapper { kWrapperNONE, kWrapperZLIB, @@ -128,10 +124,6 @@ void zlib_compress( std::string* output, bool resize_output = false) { - if (resize_output) - output->resize(zlib_estimate_compressed_size(input_size)); - size_t output_size = output->size(); - z_stream stream; memset(&stream, 0, sizeof(stream)); @@ -140,6 +132,11 @@ void zlib_compress( if (result != Z_OK) error_exit("deflateInit2 failed", result); + if (resize_output) { + output->resize(deflateBound(&stream, input_size)); + } + size_t output_size = output->size(); + stream.next_out = (Bytef*)string_data(output); stream.avail_out = (uInt)output_size; stream.next_in = (z_const Bytef*)input; @@ -299,7 +296,7 @@ void zlib_file(const char* name, // Pre-grow the output buffer so we don't measure string resize time. for (int b = 0; b < blocks; ++b) - compressed[b].resize(zlib_estimate_compressed_size(block_size)); + zlib_compress(type, input[b], input_length[b], &compressed[b], true); auto start = now(); for (int b = 0; b < blocks; ++b) @@ -307,11 +304,6 @@ void zlib_file(const char* name, zlib_compress(type, input[b], input_length[b], &compressed[b]); ctime[run] = std::chrono::duration(now() - start).count(); - // Compress again, resizing compressed, so we don't leave junk at the - // end of the compressed string that could confuse zlib_uncompress(). - for (int b = 0; b < blocks; ++b) - zlib_compress(type, input[b], input_length[b], &compressed[b], true); - for (int b = 0; b < blocks; ++b) output[b].resize(input_length[b]); diff --git a/deps/zlib/contrib/tests/fuzzers/BUILD.gn b/deps/zlib/contrib/tests/fuzzers/BUILD.gn index 16e918a720ece9..d7db4b3459bae2 100644 --- a/deps/zlib/contrib/tests/fuzzers/BUILD.gn +++ b/deps/zlib/contrib/tests/fuzzers/BUILD.gn @@ -34,6 +34,11 @@ fuzzer_test("zlib_deflate_set_dictionary_fuzzer") { deps = [ "../../../:zlib" ] } +fuzzer_test("zlib_compress_fuzzer") { + sources = [ "compress_fuzzer.cc" ] + deps = [ "../../../:zlib" ] +} + fuzzer_test("zlib_deflate_fuzzer") { sources = [ "deflate_fuzzer.cc" ] deps = [ "../../../:zlib" ] diff --git a/deps/zlib/contrib/tests/fuzzers/compress_fuzzer.cc b/deps/zlib/contrib/tests/fuzzers/compress_fuzzer.cc new file mode 100644 index 00000000000000..3afc78122be2ba --- /dev/null +++ b/deps/zlib/contrib/tests/fuzzers/compress_fuzzer.cc @@ -0,0 +1,46 @@ +// Copyright 2024 The Chromium Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include + +#include + +#include "zlib.h" + +// Fuzzer builds often have NDEBUG set, so roll our own assert macro. +#define ASSERT(cond) \ + do { \ + if (!(cond)) { \ + fprintf(stderr, "%s:%d Assert failed: %s\n", __FILE__, __LINE__, #cond); \ + exit(1); \ + } \ + } while (0) + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + FuzzedDataProvider fdp(data, size); + const int level = fdp.PickValueInArray({-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); + const std::vector src = fdp.ConsumeRemainingBytes(); + + const unsigned long compress_bound = compressBound(src.size()); + std::vector compressed; + compressed.resize(compress_bound); + + unsigned long compressed_size = compress_bound; + int ret = compress2(compressed.data(), &compressed_size, src.data(), + src.size(), level); + ASSERT(ret == Z_OK); + ASSERT(compressed_size <= compress_bound); + compressed.resize(compressed_size); + + std::vector uncompressed; + uncompressed.resize(src.size()); + unsigned long uncompressed_size = uncompressed.size(); + ret = uncompress(uncompressed.data(), &uncompressed_size, compressed.data(), + compressed.size()); + ASSERT(ret == Z_OK); + ASSERT(uncompressed_size == src.size()); + ASSERT(uncompressed == src); + + return 0; +} diff --git a/src/zlib_version.h b/src/zlib_version.h index 40a715aa6c0d05..1c55a4e5015297 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-8b7eff8" +#define ZLIB_VERSION "1.3.0.1-motley-68e57e6" #endif // SRC_ZLIB_VERSION_H_