Skip to content

Commit a41dca0

Browse files
nodejs-github-botRafaelGSS
authored andcommitted
deps: update zlib to 1.3.0.1-motley-40e35a7
PR-URL: #51274 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent 4dcc511 commit a41dca0

File tree

7 files changed

+80
-15
lines changed

7 files changed

+80
-15
lines changed

deps/zlib/BUILD.gn

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# found in the LICENSE file.
44

55
import("//build/config/compiler/compiler.gni")
6+
import("//build/config/dcheck_always_on.gni")
67

78
declare_args() {
89
# Expose zlib's symbols, used by Node.js to provide zlib APIs for its native
@@ -33,7 +34,7 @@ config("zlib_internal_config") {
3334
# Build code using -O3, see: crbug.com/1084371.
3435
configs = [ "//build/config/compiler:optimize_speed" ]
3536
}
36-
if (is_debug || use_fuzzing_engine) {
37+
if (is_debug || dcheck_always_on || use_fuzzing_engine) {
3738
# Enable zlib's asserts in debug and fuzzer builds.
3839
defines += [ "ZLIB_DEBUG" ]
3940
}

deps/zlib/contrib/tests/utils_unittest.cc

+55
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,61 @@ TEST(ZlibTest, DeflateZFixedCorruption) {
10251025
0);
10261026
}
10271027

1028+
TEST(ZlibTest, DeflateCopy) {
1029+
// Check that deflateCopy() works.
1030+
1031+
z_stream stream1;
1032+
stream1.zalloc = Z_NULL;
1033+
stream1.zfree = Z_NULL;
1034+
int ret =
1035+
deflateInit(&stream1, Z_DEFAULT_COMPRESSION);
1036+
ASSERT_EQ(ret, Z_OK);
1037+
std::vector<uint8_t> compressed(
1038+
deflateBound(&stream1, strlen(zFixedCorruptionData)));
1039+
stream1.next_out = compressed.data();
1040+
stream1.avail_out = compressed.size();
1041+
1042+
// Compress the first 1000 bytes.
1043+
stream1.next_in = (uint8_t*)zFixedCorruptionData;
1044+
stream1.avail_in = 1000;
1045+
ret = deflate(&stream1, Z_NO_FLUSH);
1046+
ASSERT_EQ(ret, Z_OK);
1047+
1048+
// Copy the stream state.
1049+
z_stream stream2;
1050+
ret = deflateCopy(&stream2, &stream1);
1051+
ASSERT_EQ(ret, Z_OK);
1052+
deflateEnd(&stream1);
1053+
1054+
// Compress the remaining bytes.
1055+
stream2.next_in = (uint8_t*)zFixedCorruptionData + (1000 - stream2.avail_in);
1056+
stream2.avail_in = strlen(zFixedCorruptionData) - (1000 - stream2.avail_in);
1057+
ret = deflate(&stream2, Z_FINISH);
1058+
ASSERT_EQ(ret, Z_STREAM_END);
1059+
size_t compressed_sz = compressed.size() - stream2.avail_out;
1060+
deflateEnd(&stream2);
1061+
1062+
// Check that decompression is successful.
1063+
std::vector<uint8_t> decompressed(strlen(zFixedCorruptionData));
1064+
z_stream stream;
1065+
stream.zalloc = Z_NULL;
1066+
stream.zfree = Z_NULL;
1067+
ret = inflateInit(&stream);
1068+
ASSERT_EQ(ret, Z_OK);
1069+
stream.next_in = compressed.data();
1070+
stream.avail_in = compressed_sz;
1071+
stream.next_out = decompressed.data();
1072+
stream.avail_out = decompressed.size();
1073+
ret = inflate(&stream, Z_FINISH);
1074+
ASSERT_EQ(ret, Z_STREAM_END);
1075+
inflateEnd(&stream);
1076+
1077+
EXPECT_EQ(decompressed.size(), strlen(zFixedCorruptionData));
1078+
EXPECT_EQ(
1079+
memcmp(zFixedCorruptionData, decompressed.data(), decompressed.size()),
1080+
0);
1081+
}
1082+
10281083
// TODO(gustavoa): make these tests run standalone.
10291084
#ifndef CMAKE_STANDALONE_UNITTESTS
10301085

deps/zlib/deflate.c

+8
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,11 @@ int ZEXPORT deflateCopy(z_streamp dest, z_streamp source) {
13451345
ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
13461346
ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
13471347
ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
1348+
#ifdef LIT_MEM
1349+
ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, 5);
1350+
#else
13481351
ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, 4);
1352+
#endif
13491353

13501354
if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
13511355
ds->pending_buf == Z_NULL) {
@@ -1356,7 +1360,11 @@ int ZEXPORT deflateCopy(z_streamp dest, z_streamp source) {
13561360
zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
13571361
zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos));
13581362
zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos));
1363+
#ifdef LIT_MEM
1364+
zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->lit_bufsize * 5);
1365+
#else
13591366
zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
1367+
#endif
13601368

13611369
ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
13621370
#ifdef LIT_MEM

deps/zlib/deflate.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
/* define LIT_MEM to slightly increase the speed of deflate (order 1% to 2%) at
2727
the cost of a larger memory footprint */
28-
/* #define LIT_MEM */
28+
#define LIT_MEM
2929

3030
/* ===========================================================================
3131
* Internal compression state.

deps/zlib/google/compression_utils.cc

+11-11
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#include "third_party/zlib/google/compression_utils.h"
66

7-
#include "base/bit_cast.h"
87
#include "base/check_op.h"
98
#include "base/process/memory.h"
109
#include "base/sys_byteorder.h"
@@ -24,8 +23,8 @@ bool GzipCompress(base::span<const char> input,
2423
// uLongf can be larger than size_t.
2524
uLongf compressed_size_long = static_cast<uLongf>(output_buffer_size);
2625
if (zlib_internal::GzipCompressHelper(
27-
base::bit_cast<Bytef*>(output_buffer), &compressed_size_long,
28-
base::bit_cast<const Bytef*>(input.data()),
26+
reinterpret_cast<Bytef*>(output_buffer), &compressed_size_long,
27+
reinterpret_cast<const Bytef*>(input.data()),
2928
static_cast<uLongf>(input.size()), malloc_fn, free_fn) != Z_OK) {
3029
return false;
3130
}
@@ -55,7 +54,7 @@ bool GzipCompress(base::span<const uint8_t> input, std::string* output) {
5554

5655
if (zlib_internal::GzipCompressHelper(
5756
compressed_data, &compressed_data_size,
58-
base::bit_cast<const Bytef*>(input.data()), input_size, nullptr,
57+
reinterpret_cast<const Bytef*>(input.data()), input_size, nullptr,
5958
nullptr) != Z_OK) {
6059
free(compressed_data);
6160
return false;
@@ -82,8 +81,8 @@ bool GzipUncompress(const std::string& input, std::string* output) {
8281

8382
uncompressed_output.resize(uncompressed_size);
8483
if (zlib_internal::GzipUncompressHelper(
85-
base::bit_cast<Bytef*>(uncompressed_output.data()),
86-
&uncompressed_size, base::bit_cast<const Bytef*>(input.data()),
84+
reinterpret_cast<Bytef*>(uncompressed_output.data()),
85+
&uncompressed_size, reinterpret_cast<const Bytef*>(input.data()),
8786
static_cast<uLongf>(input.length())) == Z_OK) {
8887
output->swap(uncompressed_output);
8988
return true;
@@ -102,8 +101,8 @@ bool GzipUncompress(base::span<const uint8_t> input,
102101
if (uncompressed_size > output.size())
103102
return false;
104103
return zlib_internal::GzipUncompressHelper(
105-
base::bit_cast<Bytef*>(output.data()), &uncompressed_size,
106-
base::bit_cast<const Bytef*>(input.data()),
104+
reinterpret_cast<Bytef*>(const_cast<uint8_t*>(output.data())),
105+
&uncompressed_size, reinterpret_cast<const Bytef*>(input.data()),
107106
static_cast<uLongf>(input.size())) == Z_OK;
108107
}
109108

@@ -117,8 +116,8 @@ bool GzipUncompress(base::span<const uint8_t> input, std::string* output) {
117116
uLongf uncompressed_size = GetUncompressedSize(input);
118117
output->resize(uncompressed_size);
119118
return zlib_internal::GzipUncompressHelper(
120-
base::bit_cast<Bytef*>(output->data()), &uncompressed_size,
121-
base::bit_cast<const Bytef*>(input.data()),
119+
reinterpret_cast<Bytef*>(output->data()), &uncompressed_size,
120+
reinterpret_cast<const Bytef*>(input.data()),
122121
static_cast<uLongf>(input.size())) == Z_OK;
123122
}
124123

@@ -128,7 +127,8 @@ uint32_t GetUncompressedSize(base::span<const char> compressed_data) {
128127

129128
uint32_t GetUncompressedSize(base::span<const uint8_t> compressed_data) {
130129
return zlib_internal::GetGzipUncompressedSize(
131-
base::bit_cast<Bytef*>(compressed_data.data()), compressed_data.size());
130+
reinterpret_cast<const Bytef*>(compressed_data.data()),
131+
compressed_data.size());
132132
}
133133

134134
} // namespace compression

deps/zlib/trees.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,8 @@ local void compress_block(deflate_state *s, const ct_data *ltree,
938938

939939
/* Check for no overlay of pending_buf on needed symbols */
940940
#ifdef LIT_MEM
941-
Assert(s->pending < (s->lit_bufsize << 1) + sx, "pendingBuf overflow");
941+
Assert(s->pending < (s->lit_bufsize << 1) + (sx << 1),
942+
"pendingBuf overflow");
942943
#else
943944
Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow");
944945
#endif

src/zlib_version.h

+1-1
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-dd5fc13"
5+
#define ZLIB_VERSION "1.3.0.1-motley-40e35a7"
66
#endif // SRC_ZLIB_VERSION_H_

0 commit comments

Comments
 (0)