Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: update zlib to 1.3.0.1-motley-40e35a7 #51274

Merged
merged 1 commit into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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-dd5fc13"
#define ZLIB_VERSION "1.3.0.1-motley-40e35a7"
#endif // SRC_ZLIB_VERSION_H_