Skip to content

Commit

Permalink
deps: update zlib to 1.3.0.1-motley-40e35a7
Browse files Browse the repository at this point in the history
PR-URL: #51274
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
  • Loading branch information
nodejs-github-bot authored and richardlau committed Mar 20, 2024
1 parent 57a38c8 commit 7bea2d7
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 17 deletions.
3 changes: 2 additions & 1 deletion deps/zlib/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# found in the LICENSE file.

import("//build/config/compiler/compiler.gni")
import("//build/config/dcheck_always_on.gni")

declare_args() {
# Expose zlib's symbols, used by Node.js to provide zlib APIs for its native
Expand Down Expand Up @@ -33,7 +34,7 @@ config("zlib_internal_config") {
# Build code using -O3, see: crbug.com/1084371.
configs = [ "//build/config/compiler:optimize_speed" ]
}
if (is_debug || use_fuzzing_engine) {
if (is_debug || dcheck_always_on || use_fuzzing_engine) {
# Enable zlib's asserts in debug and fuzzer builds.
defines += [ "ZLIB_DEBUG" ]
}
Expand Down
55 changes: 55 additions & 0 deletions deps/zlib/contrib/tests/utils_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,61 @@ TEST(ZlibTest, DeflateZFixedCorruption) {
0);
}

TEST(ZlibTest, DeflateCopy) {
// Check that deflateCopy() works.

z_stream stream1;
stream1.zalloc = Z_NULL;
stream1.zfree = Z_NULL;
int ret =
deflateInit(&stream1, Z_DEFAULT_COMPRESSION);
ASSERT_EQ(ret, Z_OK);
std::vector<uint8_t> compressed(
deflateBound(&stream1, strlen(zFixedCorruptionData)));
stream1.next_out = compressed.data();
stream1.avail_out = compressed.size();

// Compress the first 1000 bytes.
stream1.next_in = (uint8_t*)zFixedCorruptionData;
stream1.avail_in = 1000;
ret = deflate(&stream1, Z_NO_FLUSH);
ASSERT_EQ(ret, Z_OK);

// Copy the stream state.
z_stream stream2;
ret = deflateCopy(&stream2, &stream1);
ASSERT_EQ(ret, Z_OK);
deflateEnd(&stream1);

// Compress the remaining bytes.
stream2.next_in = (uint8_t*)zFixedCorruptionData + (1000 - stream2.avail_in);
stream2.avail_in = strlen(zFixedCorruptionData) - (1000 - stream2.avail_in);
ret = deflate(&stream2, Z_FINISH);
ASSERT_EQ(ret, Z_STREAM_END);
size_t compressed_sz = compressed.size() - stream2.avail_out;
deflateEnd(&stream2);

// Check that decompression is successful.
std::vector<uint8_t> decompressed(strlen(zFixedCorruptionData));
z_stream stream;
stream.zalloc = Z_NULL;
stream.zfree = Z_NULL;
ret = inflateInit(&stream);
ASSERT_EQ(ret, Z_OK);
stream.next_in = compressed.data();
stream.avail_in = compressed_sz;
stream.next_out = decompressed.data();
stream.avail_out = decompressed.size();
ret = inflate(&stream, Z_FINISH);
ASSERT_EQ(ret, Z_STREAM_END);
inflateEnd(&stream);

EXPECT_EQ(decompressed.size(), strlen(zFixedCorruptionData));
EXPECT_EQ(
memcmp(zFixedCorruptionData, decompressed.data(), decompressed.size()),
0);
}

// TODO(gustavoa): make these tests run standalone.
#ifndef CMAKE_STANDALONE_UNITTESTS

Expand Down
8 changes: 8 additions & 0 deletions deps/zlib/deflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,11 @@ int ZEXPORT deflateCopy(z_streamp dest, z_streamp source) {
ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
#ifdef LIT_MEM
ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, 5);
#else
ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, 4);
#endif

if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
ds->pending_buf == Z_NULL) {
Expand All @@ -1356,7 +1360,11 @@ int ZEXPORT deflateCopy(z_streamp dest, z_streamp source) {
zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos));
zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos));
#ifdef LIT_MEM
zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->lit_bufsize * 5);
#else
zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
#endif

ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
#ifdef LIT_MEM
Expand Down
2 changes: 1 addition & 1 deletion deps/zlib/deflate.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

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

/* ===========================================================================
* Internal compression state.
Expand Down
22 changes: 11 additions & 11 deletions deps/zlib/google/compression_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

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

#include "base/bit_cast.h"
#include "base/check_op.h"
#include "base/process/memory.h"
#include "base/sys_byteorder.h"
Expand All @@ -24,8 +23,8 @@ bool GzipCompress(base::span<const char> input,
// uLongf can be larger than size_t.
uLongf compressed_size_long = static_cast<uLongf>(output_buffer_size);
if (zlib_internal::GzipCompressHelper(
base::bit_cast<Bytef*>(output_buffer), &compressed_size_long,
base::bit_cast<const Bytef*>(input.data()),
reinterpret_cast<Bytef*>(output_buffer), &compressed_size_long,
reinterpret_cast<const Bytef*>(input.data()),
static_cast<uLongf>(input.size()), malloc_fn, free_fn) != Z_OK) {
return false;
}
Expand Down Expand Up @@ -55,7 +54,7 @@ bool GzipCompress(base::span<const uint8_t> input, std::string* output) {

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

uncompressed_output.resize(uncompressed_size);
if (zlib_internal::GzipUncompressHelper(
base::bit_cast<Bytef*>(uncompressed_output.data()),
&uncompressed_size, base::bit_cast<const Bytef*>(input.data()),
reinterpret_cast<Bytef*>(uncompressed_output.data()),
&uncompressed_size, reinterpret_cast<const Bytef*>(input.data()),
static_cast<uLongf>(input.length())) == Z_OK) {
output->swap(uncompressed_output);
return true;
Expand All @@ -102,8 +101,8 @@ bool GzipUncompress(base::span<const uint8_t> input,
if (uncompressed_size > output.size())
return false;
return zlib_internal::GzipUncompressHelper(
base::bit_cast<Bytef*>(output.data()), &uncompressed_size,
base::bit_cast<const Bytef*>(input.data()),
reinterpret_cast<Bytef*>(const_cast<uint8_t*>(output.data())),
&uncompressed_size, reinterpret_cast<const Bytef*>(input.data()),
static_cast<uLongf>(input.size())) == Z_OK;
}

Expand All @@ -117,8 +116,8 @@ bool GzipUncompress(base::span<const uint8_t> input, std::string* output) {
uLongf uncompressed_size = GetUncompressedSize(input);
output->resize(uncompressed_size);
return zlib_internal::GzipUncompressHelper(
base::bit_cast<Bytef*>(output->data()), &uncompressed_size,
base::bit_cast<const Bytef*>(input.data()),
reinterpret_cast<Bytef*>(output->data()), &uncompressed_size,
reinterpret_cast<const Bytef*>(input.data()),
static_cast<uLongf>(input.size())) == Z_OK;
}

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

uint32_t GetUncompressedSize(base::span<const uint8_t> compressed_data) {
return zlib_internal::GetGzipUncompressedSize(
base::bit_cast<Bytef*>(compressed_data.data()), compressed_data.size());
reinterpret_cast<const Bytef*>(compressed_data.data()),
compressed_data.size());
}

} // namespace compression
3 changes: 2 additions & 1 deletion deps/zlib/trees.c
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,8 @@ local void compress_block(deflate_state *s, const ct_data *ltree,

/* Check for no overlay of pending_buf on needed symbols */
#ifdef LIT_MEM
Assert(s->pending < (s->lit_bufsize << 1) + sx, "pendingBuf overflow");
Assert(s->pending < (s->lit_bufsize << 1) + (sx << 1),
"pendingBuf overflow");
#else
Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow");
#endif
Expand Down
6 changes: 3 additions & 3 deletions doc/contributing/maintaining/maintaining-dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ This a list of all the dependencies:
* [uv][]
* [uvwasi 0.0.19][]
* [V8][]
* [zlib 1.3.0.1-motley-dd5fc13][]
* [zlib][]

Any code which meets one or more of these conditions should
be managed as a dependency:
Expand Down Expand Up @@ -304,7 +304,7 @@ See [maintaining-web-assembly][] for more informations.
high-performance JavaScript and WebAssembly engine, written in C++.
See [maintaining-V8][] for more informations.

### zlib 1.3.0.1-motley-dd5fc13
### zlib

The [zlib](https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/zlib)
dependency lossless data-compression library,
Expand Down Expand Up @@ -341,4 +341,4 @@ performance improvements not currently available in standard zlib.
[uv]: #uv
[uvwasi 0.0.19]: #uvwasi-0019
[v8]: #v8
[zlib 1.3.0.1-motley-dd5fc13]: #zlib-1301-motley-dd5fc13
[zlib]: #zlib

0 comments on commit 7bea2d7

Please sign in to comment.