Skip to content

Commit

Permalink
deps: update zlib to 1.2.13.1-motley-fef5869
Browse files Browse the repository at this point in the history
PR-URL: nodejs#50085
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
  • Loading branch information
nodejs-github-bot authored and alexfernandez committed Nov 1, 2023
1 parent c970704 commit ecbf298
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 136 deletions.
53 changes: 53 additions & 0 deletions deps/zlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ check_include_file(stddef.h HAVE_STDDEF_H)
option(ENABLE_SIMD_OPTIMIZATIONS "Enable all SIMD optimizations" OFF)
option(ENABLE_SIMD_AVX512 "Enable SIMD AXV512 optimizations" OFF)
option(USE_ZLIB_RABIN_KARP_HASH "Enable bitstream compatibility with canonical zlib" OFF)
option(BUILD_UNITTESTS "Enable standalone unit tests build" OFF)

if (USE_ZLIB_RABIN_KARP_HASH)
add_definitions(-DUSE_ZLIB_RABIN_KARP_ROLLING_HASH)
Expand Down Expand Up @@ -244,6 +245,58 @@ set(CMAKE_CXX_STANDARD 14) # workaround for older compilers (e.g. g++ 5.4).
add_executable(zlib_bench contrib/bench/zlib_bench.cc)
target_link_libraries(zlib_bench zlib)

#============================================================================
# Unit Tests
#============================================================================
if (BUILD_UNITTESTS)
include (ExternalProject)
set_directory_properties(PROPERTIES EP_PREFIX ${CMAKE_BINARY_DIR}/third_party)
ExternalProject_add(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG d1467f5813f4d363cfd11aba99c4e9fe47a85e99
UPDATE_COMMAND ""
INSTALL_COMMAND ""
LOG_DOWNLOAD ON
LOG_CONFIGURE ON
LOG_BUILD ON
)

# gtest includedir
ExternalProject_Get_Property(googletest source_dir)
set(GTEST_INCLUDE_DIRS
${source_dir}/googletest/include
${source_dir}/googletest/include/gtest
)

# gtest library
ExternalProject_Get_Property(googletest binary_dir)
set(GTEST_LIBRARY_PATH ${binary_dir}/lib/${CMAKE_FIND_LIBRARY_PREFIXES}gtest.a)
set(GTEST_LIBRARY gtest)
add_library(${GTEST_LIBRARY} UNKNOWN IMPORTED)
set_property(TARGET ${GTEST_LIBRARY} PROPERTY IMPORTED_LOCATION ${GTEST_LIBRARY_PATH})
add_dependencies(${GTEST_LIBRARY} googletest)

set(UTEST_SRC
${CMAKE_CURRENT_SOURCE_DIR}/contrib/tests/infcover.cc
${CMAKE_CURRENT_SOURCE_DIR}/contrib/tests/infcover.h
${CMAKE_CURRENT_SOURCE_DIR}/contrib/tests/utils_unittest.cc
${CMAKE_CURRENT_SOURCE_DIR}/contrib/tests/standalone_test_runner.cc
${CMAKE_CURRENT_SOURCE_DIR}/google/compression_utils_portable.cc
)

add_compile_definitions(CMAKE_STANDALONE_UNITTESTS)

add_executable(zlib_unittests ${UTEST_SRC})
target_include_directories(zlib_unittests PUBLIC ${GTEST_INCLUDE_DIRS})
target_include_directories(zlib_unittests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/google)

target_link_libraries(zlib_unittests ${GTEST_LIBRARY})
target_link_libraries(zlib_unittests zlib)
# Needed by gtest
target_link_libraries(zlib_unittests pthread)
endif()

#============================================================================
# Minigzip tool
#============================================================================
Expand Down
2 changes: 1 addition & 1 deletion deps/zlib/README.chromium
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Version: 1.2.13
CPEPrefix: cpe:/a:zlib:zlib:1.2.13
Security Critical: yes
Shipped: yes
License: Custom license
License: Zlib
License File: LICENSE
License Android Compatible: yes

Expand Down
5 changes: 3 additions & 2 deletions deps/zlib/contrib/optimizations/inflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1488,8 +1488,9 @@ int ZEXPORT inflateCopy(z_streamp dest, z_streamp source) {
if (copy == Z_NULL) return Z_MEM_ERROR;
window = Z_NULL;
if (state->window != Z_NULL) {
window = (unsigned char FAR *)
ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
window = (unsigned char FAR *)ZALLOC(
source, (1U << state->wbits) + CHUNKCOPY_CHUNK_SIZE,
sizeof(unsigned char));
if (window == Z_NULL) {
ZFREE(source, copy);
return Z_MEM_ERROR;
Expand Down
97 changes: 16 additions & 81 deletions deps/zlib/contrib/optimizations/insert_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,64 +16,7 @@
#endif
#endif

#include "cpu_features.h"

// clang-format off
#if defined(CRC32_SIMD_SSE42_PCLMUL)
#include <smmintrin.h> /* Required to make MSVC bot build pass. */

#if defined(__clang__) || defined(__GNUC__)
#define TARGET_CPU_WITH_CRC __attribute__((target("sse4.2")))
#else
#define TARGET_CPU_WITH_CRC
#endif

/* CRC32C uint32_t */
#define _cpu_crc32c_hash_u32 _mm_crc32_u32

#elif defined(CRC32_ARMV8_CRC32)
#if defined(__clang__)
#define __crc32cw __builtin_arm_crc32cw
#elif defined(__GNUC__)
#define __crc32cw __builtin_aarch64_crc32cw
#endif

#if defined(__aarch64__) && defined(__clang__)
#define TARGET_CPU_WITH_CRC __attribute__((target("crc")))
#elif defined(__aarch64__) && defined(__GNUC__)
#define TARGET_CPU_WITH_CRC __attribute__((target("+crc")))
#elif defined(__clang__) // !defined(__aarch64__)
#define TARGET_CPU_WITH_CRC __attribute__((target("armv8-a,crc")))
#endif // defined(__aarch64__)

/* CRC32C uint32_t */
#define _cpu_crc32c_hash_u32 __crc32cw

#endif
// clang-format on

#if defined(TARGET_CPU_WITH_CRC)

TARGET_CPU_WITH_CRC
local INLINE Pos insert_string_simd(deflate_state* const s, const Pos str) {
Pos ret;
unsigned val, h = 0;

zmemcpy(&val, &s->window[str], sizeof(val));

if (s->level >= 6)
val &= 0xFFFFFF;

/* Compute hash from the CRC32C of |val|. */
h = _cpu_crc32c_hash_u32(h, val);

ret = s->head[h & s->hash_mask];
s->head[h & s->hash_mask] = str;
s->prev[str & s->w_mask] = ret;
return ret;
}

#endif // TARGET_CPU_WITH_CRC
#include <stdint.h>

/**
* Some applications need to match zlib DEFLATE output exactly [3]. Use the
Expand Down Expand Up @@ -107,10 +50,23 @@ local INLINE Pos insert_string_simd(deflate_state* const s, const Pos str) {
* characters and the first MIN_MATCH bytes of str are valid (except for
* the last MIN_MATCH-1 bytes of the input file).
*/
local INLINE Pos insert_string_c(deflate_state* const s, const Pos str) {
local INLINE Pos insert_string(deflate_state* const s, const Pos str) {
Pos ret;

/* insert_string dictionary insertion: ANZAC++ hasher
* significantly improves data compression speed.
*
* Note: the generated compressed output is a valid DEFLATE stream, but will
* differ from canonical zlib output.
*/
#if defined(USE_ZLIB_RABIN_KARP_ROLLING_HASH)
UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH - 1)]);
#else
uint32_t value;
// Validated for little endian archs (i.e. x86, Arm). YMMV for big endian.
zmemcpy(&value, &s->window[str], sizeof(value));
s->ins_h = ((value * 66521 + 66521) >> 16) & s->hash_mask;
#endif

#ifdef FASTEST
ret = s->head[s->ins_h];
#else
Expand All @@ -121,25 +77,4 @@ local INLINE Pos insert_string_c(deflate_state* const s, const Pos str) {
return ret;
}

local INLINE Pos insert_string(deflate_state* const s, const Pos str) {
/* insert_string_simd string dictionary insertion: SIMD crc32c symbol hasher
* significantly improves data compression speed.
*
* Note: the generated compressed output is a valid DEFLATE stream, but will
* differ from canonical zlib output.
*/
#if defined(USE_ZLIB_RABIN_KARP_ROLLING_HASH)
/* So this build-time option can be used to disable the crc32c hash, and use
* the Rabin-Karp hash instead.
*/ /* FALLTHROUGH Rabin-Karp */
#elif defined(TARGET_CPU_WITH_CRC) && defined(CRC32_SIMD_SSE42_PCLMUL)
if (x86_cpu_enable_simd)
return insert_string_simd(s, str);
#elif defined(TARGET_CPU_WITH_CRC) && defined(CRC32_ARMV8_CRC32)
if (arm_cpu_enable_crc32)
return insert_string_simd(s, str);
#endif
return insert_string_c(s, str); /* Rabin-Karp */
}

#endif /* INSERT_STRING_H */
9 changes: 9 additions & 0 deletions deps/zlib/contrib/tests/standalone_test_runner.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the Chromium source repository LICENSE file.
#include <gtest/gtest.h>

int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
14 changes: 12 additions & 2 deletions deps/zlib/contrib/tests/utils_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@
#include <cstddef>
#include <vector>

#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
#include "compression_utils_portable.h"
#include "gtest.h"

#if !defined(CMAKE_STANDALONE_UNITTESTS)
#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"

#include "third_party/zlib/contrib/minizip/unzip.h"
#include "third_party/zlib/contrib/minizip/zip.h"
#endif

#include "zlib.h"

void TestPayloads(size_t input_size, zlib_internal::WrapperType type) {
Expand Down Expand Up @@ -1020,6 +1025,9 @@ TEST(ZlibTest, DeflateZFixedCorruption) {
0);
}

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

TEST(ZlibTest, ZipFilenameCommentSize) {
// Check that minizip rejects zip member filenames or comments longer than
// the zip format can represent.
Expand Down Expand Up @@ -1138,3 +1146,5 @@ TEST(ZlibTest, ZipExtraFieldSize) {
EXPECT_EQ(unzGoToNextFile(uzf), UNZ_END_OF_LIST_OF_FILE);
EXPECT_EQ(unzClose(uzf), UNZ_OK);
}

#endif
10 changes: 2 additions & 8 deletions deps/zlib/deflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,15 +457,9 @@ int ZEXPORT deflateInit2_(z_streamp strm, int level, int method,
s->w_size = 1 << s->w_bits;
s->w_mask = s->w_size - 1;

s->chromium_zlib_hash = 1;
#if defined(USE_ZLIB_RABIN_KARP_ROLLING_HASH)
s->chromium_zlib_hash = 0;
#if !defined(USE_ZLIB_RABIN_KARP_ROLLING_HASH)
#if defined(TARGET_CPU_WITH_CRC) && defined(CRC32_SIMD_SSE42_PCLMUL)
if (x86_cpu_enable_simd)
s->chromium_zlib_hash = 1;
#elif defined(TARGET_CPU_WITH_CRC) && defined(CRC32_ARMV8_CRC32)
if (arm_cpu_enable_crc32)
s->chromium_zlib_hash = 1;
#endif
#endif

s->hash_bits = memLevel + 7;
Expand Down
3 changes: 2 additions & 1 deletion deps/zlib/google/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ include_rules = [
'+base',
'+build',
'+testing',
"+third_party/zlib/zlib.h",
'+third_party/icu/source/i18n/unicode',
'+third_party/zlib/zlib.h',
]
13 changes: 7 additions & 6 deletions deps/zlib/google/zip_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,13 @@ zip_fileinfo TimeToZipFileInfo(const base::Time& file_time) {
// It assumes that dates below 1980 are in the double digit format.
// Hence the fail safe option is to leave the date unset. Some programs
// might show the unset date as 1980-0-0 which is invalid.
zip_info.tmz_date.tm_year = file_time_parts.year;
zip_info.tmz_date.tm_mon = file_time_parts.month - 1;
zip_info.tmz_date.tm_mday = file_time_parts.day_of_month;
zip_info.tmz_date.tm_hour = file_time_parts.hour;
zip_info.tmz_date.tm_min = file_time_parts.minute;
zip_info.tmz_date.tm_sec = file_time_parts.second;
zip_info.tmz_date = {
.tm_sec = static_cast<uInt>(file_time_parts.second),
.tm_min = static_cast<uInt>(file_time_parts.minute),
.tm_hour = static_cast<uInt>(file_time_parts.hour),
.tm_mday = static_cast<uInt>(file_time_parts.day_of_month),
.tm_mon = static_cast<uInt>(file_time_parts.month - 1),
.tm_year = static_cast<uInt>(file_time_parts.year)};
}

return zip_info;
Expand Down
16 changes: 8 additions & 8 deletions deps/zlib/google/zip_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,14 @@ bool ZipReader::OpenEntry() {

// Construct the last modified time. The timezone info is not present in ZIP
// archives, so we construct the time as UTC.
base::Time::Exploded exploded_time = {};
exploded_time.year = info.tmu_date.tm_year;
exploded_time.month = info.tmu_date.tm_mon + 1; // 0-based vs 1-based
exploded_time.day_of_month = info.tmu_date.tm_mday;
exploded_time.hour = info.tmu_date.tm_hour;
exploded_time.minute = info.tmu_date.tm_min;
exploded_time.second = info.tmu_date.tm_sec;
exploded_time.millisecond = 0;
const base::Time::Exploded exploded_time = {
.year = static_cast<int>(info.tmu_date.tm_year),
.month =
static_cast<int>(info.tmu_date.tm_mon + 1), // 0-based vs 1-based
.day_of_month = static_cast<int>(info.tmu_date.tm_mday),
.hour = static_cast<int>(info.tmu_date.tm_hour),
.minute = static_cast<int>(info.tmu_date.tm_min),
.second = static_cast<int>(info.tmu_date.tm_sec)};

if (!base::Time::FromUTCExploded(exploded_time, &entry_.last_modified))
entry_.last_modified = base::Time::UnixEpoch();
Expand Down
34 changes: 10 additions & 24 deletions deps/zlib/google/zip_reader_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/hash/md5.h"
#include "base/i18n/time_formatting.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/strings/string_piece.h"
Expand All @@ -31,6 +32,7 @@
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
#include "third_party/icu/source/i18n/unicode/timezone.h"
#include "third_party/zlib/google/zip_internal.h"

using ::testing::_;
Expand Down Expand Up @@ -288,18 +290,10 @@ TEST_F(ZipReaderTest, RegularFile) {

EXPECT_EQ(target_path, entry->path);
EXPECT_EQ(13527, entry->original_size);

// The expected time stamp: 2009-05-29 06:22:20
base::Time::Exploded exploded = {}; // Zero-clear.
entry->last_modified.UTCExplode(&exploded);
EXPECT_EQ(2009, exploded.year);
EXPECT_EQ(5, exploded.month);
EXPECT_EQ(29, exploded.day_of_month);
EXPECT_EQ(6, exploded.hour);
EXPECT_EQ(22, exploded.minute);
EXPECT_EQ(20, exploded.second);
EXPECT_EQ(0, exploded.millisecond);

EXPECT_EQ("2009-05-29 06:22:20.000",
base::UnlocalizedTimeFormatWithPattern(entry->last_modified,
"y-MM-dd HH:mm:ss.SSS",
icu::TimeZone::getGMT()));
EXPECT_FALSE(entry->is_unsafe);
EXPECT_FALSE(entry->is_directory);
}
Expand Down Expand Up @@ -396,18 +390,10 @@ TEST_F(ZipReaderTest, Directory) {
EXPECT_EQ(target_path, entry->path);
// The directory size should be zero.
EXPECT_EQ(0, entry->original_size);

// The expected time stamp: 2009-05-31 15:49:52
base::Time::Exploded exploded = {}; // Zero-clear.
entry->last_modified.UTCExplode(&exploded);
EXPECT_EQ(2009, exploded.year);
EXPECT_EQ(5, exploded.month);
EXPECT_EQ(31, exploded.day_of_month);
EXPECT_EQ(15, exploded.hour);
EXPECT_EQ(49, exploded.minute);
EXPECT_EQ(52, exploded.second);
EXPECT_EQ(0, exploded.millisecond);

EXPECT_EQ("2009-05-31 15:49:52.000",
base::UnlocalizedTimeFormatWithPattern(entry->last_modified,
"y-MM-dd HH:mm:ss.SSS",
icu::TimeZone::getGMT()));
EXPECT_FALSE(entry->is_unsafe);
EXPECT_TRUE(entry->is_directory);
}
Expand Down
Loading

0 comments on commit ecbf298

Please sign in to comment.