Skip to content

Commit 654c8d1

Browse files
nodejs-github-bottargos
authored andcommitted
deps: update zlib to 1.3.0.1-motley-68e57e6
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>
1 parent 2477e79 commit 654c8d1

File tree

4 files changed

+58
-15
lines changed

4 files changed

+58
-15
lines changed

deps/zlib/contrib/bench/zlib_bench.cc

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ Data read_file_data_or_exit(const char* name) {
7171
return data;
7272
}
7373

74-
size_t zlib_estimate_compressed_size(size_t input_size) {
75-
return compressBound(input_size);
76-
}
77-
7874
enum zlib_wrapper {
7975
kWrapperNONE,
8076
kWrapperZLIB,
@@ -128,10 +124,6 @@ void zlib_compress(
128124
std::string* output,
129125
bool resize_output = false)
130126
{
131-
if (resize_output)
132-
output->resize(zlib_estimate_compressed_size(input_size));
133-
size_t output_size = output->size();
134-
135127
z_stream stream;
136128
memset(&stream, 0, sizeof(stream));
137129

@@ -140,6 +132,11 @@ void zlib_compress(
140132
if (result != Z_OK)
141133
error_exit("deflateInit2 failed", result);
142134

135+
if (resize_output) {
136+
output->resize(deflateBound(&stream, input_size));
137+
}
138+
size_t output_size = output->size();
139+
143140
stream.next_out = (Bytef*)string_data(output);
144141
stream.avail_out = (uInt)output_size;
145142
stream.next_in = (z_const Bytef*)input;
@@ -299,19 +296,14 @@ void zlib_file(const char* name,
299296

300297
// Pre-grow the output buffer so we don't measure string resize time.
301298
for (int b = 0; b < blocks; ++b)
302-
compressed[b].resize(zlib_estimate_compressed_size(block_size));
299+
zlib_compress(type, input[b], input_length[b], &compressed[b], true);
303300

304301
auto start = now();
305302
for (int b = 0; b < blocks; ++b)
306303
for (int r = 0; r < repeats; ++r)
307304
zlib_compress(type, input[b], input_length[b], &compressed[b]);
308305
ctime[run] = std::chrono::duration<double>(now() - start).count();
309306

310-
// Compress again, resizing compressed, so we don't leave junk at the
311-
// end of the compressed string that could confuse zlib_uncompress().
312-
for (int b = 0; b < blocks; ++b)
313-
zlib_compress(type, input[b], input_length[b], &compressed[b], true);
314-
315307
for (int b = 0; b < blocks; ++b)
316308
output[b].resize(input_length[b]);
317309

deps/zlib/contrib/tests/fuzzers/BUILD.gn

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ fuzzer_test("zlib_deflate_set_dictionary_fuzzer") {
3434
deps = [ "../../../:zlib" ]
3535
}
3636

37+
fuzzer_test("zlib_compress_fuzzer") {
38+
sources = [ "compress_fuzzer.cc" ]
39+
deps = [ "../../../:zlib" ]
40+
}
41+
3742
fuzzer_test("zlib_deflate_fuzzer") {
3843
sources = [ "deflate_fuzzer.cc" ]
3944
deps = [ "../../../:zlib" ]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2024 The Chromium Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include <fuzzer/FuzzedDataProvider.h>
6+
7+
#include <vector>
8+
9+
#include "zlib.h"
10+
11+
// Fuzzer builds often have NDEBUG set, so roll our own assert macro.
12+
#define ASSERT(cond) \
13+
do { \
14+
if (!(cond)) { \
15+
fprintf(stderr, "%s:%d Assert failed: %s\n", __FILE__, __LINE__, #cond); \
16+
exit(1); \
17+
} \
18+
} while (0)
19+
20+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
21+
FuzzedDataProvider fdp(data, size);
22+
const int level = fdp.PickValueInArray({-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
23+
const std::vector<uint8_t> src = fdp.ConsumeRemainingBytes<uint8_t>();
24+
25+
const unsigned long compress_bound = compressBound(src.size());
26+
std::vector<uint8_t> compressed;
27+
compressed.resize(compress_bound);
28+
29+
unsigned long compressed_size = compress_bound;
30+
int ret = compress2(compressed.data(), &compressed_size, src.data(),
31+
src.size(), level);
32+
ASSERT(ret == Z_OK);
33+
ASSERT(compressed_size <= compress_bound);
34+
compressed.resize(compressed_size);
35+
36+
std::vector<uint8_t> uncompressed;
37+
uncompressed.resize(src.size());
38+
unsigned long uncompressed_size = uncompressed.size();
39+
ret = uncompress(uncompressed.data(), &uncompressed_size, compressed.data(),
40+
compressed.size());
41+
ASSERT(ret == Z_OK);
42+
ASSERT(uncompressed_size == src.size());
43+
ASSERT(uncompressed == src);
44+
45+
return 0;
46+
}

src/zlib_version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
// Refer to tools/dep_updaters/update-zlib.sh
33
#ifndef SRC_ZLIB_VERSION_H_
44
#define SRC_ZLIB_VERSION_H_
5-
#define ZLIB_VERSION "1.3.0.1-motley-8b7eff8"
5+
#define ZLIB_VERSION "1.3.0.1-motley-68e57e6"
66
#endif // SRC_ZLIB_VERSION_H_

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy