Skip to content

Commit

Permalink
deps: update zlib to 1.3.0.1-motley-68e57e6
Browse files Browse the repository at this point in the history
PR-URL: #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>
  • Loading branch information
nodejs-github-bot authored and targos committed Aug 14, 2024
1 parent 713ae95 commit e7db639
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 15 deletions.
20 changes: 6 additions & 14 deletions deps/zlib/contrib/bench/zlib_bench.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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));

Expand All @@ -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;
Expand Down Expand Up @@ -299,19 +296,14 @@ 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)
for (int r = 0; r < repeats; ++r)
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]);

Expand Down
5 changes: 5 additions & 0 deletions deps/zlib/contrib/tests/fuzzers/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand Down
46 changes: 46 additions & 0 deletions deps/zlib/contrib/tests/fuzzers/compress_fuzzer.cc
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 1 addition & 1 deletion src/zlib_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_

0 comments on commit e7db639

Please sign in to comment.