deps: update zlib to 1.3.0.1-motley-68e57e6

PR-URL: https://github.com/nodejs/node/pull/53464
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Node.js GitHub Bot
2024-07-07 00:28:55 +00:00
parent ab214322f8
commit 0c17a3fb38
4 changed files with 58 additions and 15 deletions

View File

@@ -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<double>(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]);

View File

@@ -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" ]

View File

@@ -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 <fuzzer/FuzzedDataProvider.h>
#include <vector>
#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<uint8_t> src = fdp.ConsumeRemainingBytes<uint8_t>();
const unsigned long compress_bound = compressBound(src.size());
std::vector<uint8_t> 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<uint8_t> 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;
}

View File

@@ -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_