diff --git a/graal-nodejs/deps/zlib/CMakeLists.txt b/graal-nodejs/deps/zlib/CMakeLists.txt index 471a3a46a09..234eab8db41 100644 --- a/graal-nodejs/deps/zlib/CMakeLists.txt +++ b/graal-nodejs/deps/zlib/CMakeLists.txt @@ -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) @@ -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 #============================================================================ diff --git a/graal-nodejs/deps/zlib/README.chromium b/graal-nodejs/deps/zlib/README.chromium index 663ee0521ed..1dfb9966642 100644 --- a/graal-nodejs/deps/zlib/README.chromium +++ b/graal-nodejs/deps/zlib/README.chromium @@ -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 diff --git a/graal-nodejs/deps/zlib/contrib/optimizations/inflate.c b/graal-nodejs/deps/zlib/contrib/optimizations/inflate.c index 6ed87160f53..2a8e0ef76db 100644 --- a/graal-nodejs/deps/zlib/contrib/optimizations/inflate.c +++ b/graal-nodejs/deps/zlib/contrib/optimizations/inflate.c @@ -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; diff --git a/graal-nodejs/deps/zlib/contrib/optimizations/insert_string.h b/graal-nodejs/deps/zlib/contrib/optimizations/insert_string.h index c6a296aef73..260b8268029 100644 --- a/graal-nodejs/deps/zlib/contrib/optimizations/insert_string.h +++ b/graal-nodejs/deps/zlib/contrib/optimizations/insert_string.h @@ -16,64 +16,7 @@ #endif #endif -#include "cpu_features.h" - -// clang-format off -#if defined(CRC32_SIMD_SSE42_PCLMUL) - #include /* 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 /** * Some applications need to match zlib DEFLATE output exactly [3]. Use the @@ -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 @@ -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 */ diff --git a/graal-nodejs/deps/zlib/contrib/tests/standalone_test_runner.cc b/graal-nodejs/deps/zlib/contrib/tests/standalone_test_runner.cc new file mode 100644 index 00000000000..1ec9c30bacb --- /dev/null +++ b/graal-nodejs/deps/zlib/contrib/tests/standalone_test_runner.cc @@ -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 + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/graal-nodejs/deps/zlib/contrib/tests/utils_unittest.cc b/graal-nodejs/deps/zlib/contrib/tests/utils_unittest.cc index 7270d0af908..d06dbc9812a 100644 --- a/graal-nodejs/deps/zlib/contrib/tests/utils_unittest.cc +++ b/graal-nodejs/deps/zlib/contrib/tests/utils_unittest.cc @@ -7,12 +7,17 @@ #include #include -#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) { @@ -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. @@ -1138,3 +1146,5 @@ TEST(ZlibTest, ZipExtraFieldSize) { EXPECT_EQ(unzGoToNextFile(uzf), UNZ_END_OF_LIST_OF_FILE); EXPECT_EQ(unzClose(uzf), UNZ_OK); } + +#endif diff --git a/graal-nodejs/deps/zlib/deflate.c b/graal-nodejs/deps/zlib/deflate.c index 1fa55e5d010..173ce596be5 100644 --- a/graal-nodejs/deps/zlib/deflate.c +++ b/graal-nodejs/deps/zlib/deflate.c @@ -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; diff --git a/graal-nodejs/deps/zlib/google/DEPS b/graal-nodejs/deps/zlib/google/DEPS index 03f2cb950b9..7ec5343ee23 100644 --- a/graal-nodejs/deps/zlib/google/DEPS +++ b/graal-nodejs/deps/zlib/google/DEPS @@ -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', ] diff --git a/graal-nodejs/deps/zlib/google/zip_internal.cc b/graal-nodejs/deps/zlib/google/zip_internal.cc index 9b20b421e24..b9976d63ee3 100644 --- a/graal-nodejs/deps/zlib/google/zip_internal.cc +++ b/graal-nodejs/deps/zlib/google/zip_internal.cc @@ -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(file_time_parts.second), + .tm_min = static_cast(file_time_parts.minute), + .tm_hour = static_cast(file_time_parts.hour), + .tm_mday = static_cast(file_time_parts.day_of_month), + .tm_mon = static_cast(file_time_parts.month - 1), + .tm_year = static_cast(file_time_parts.year)}; } return zip_info; diff --git a/graal-nodejs/deps/zlib/google/zip_reader.cc b/graal-nodejs/deps/zlib/google/zip_reader.cc index 9b1030a029c..34a815e5f52 100644 --- a/graal-nodejs/deps/zlib/google/zip_reader.cc +++ b/graal-nodejs/deps/zlib/google/zip_reader.cc @@ -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(info.tmu_date.tm_year), + .month = + static_cast(info.tmu_date.tm_mon + 1), // 0-based vs 1-based + .day_of_month = static_cast(info.tmu_date.tm_mday), + .hour = static_cast(info.tmu_date.tm_hour), + .minute = static_cast(info.tmu_date.tm_min), + .second = static_cast(info.tmu_date.tm_sec)}; if (!base::Time::FromUTCExploded(exploded_time, &entry_.last_modified)) entry_.last_modified = base::Time::UnixEpoch(); diff --git a/graal-nodejs/deps/zlib/google/zip_reader_unittest.cc b/graal-nodejs/deps/zlib/google/zip_reader_unittest.cc index b9175045d07..6086c97c49b 100644 --- a/graal-nodejs/deps/zlib/google/zip_reader_unittest.cc +++ b/graal-nodejs/deps/zlib/google/zip_reader_unittest.cc @@ -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" @@ -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::_; @@ -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); } @@ -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); } diff --git a/graal-nodejs/doc/contributing/maintaining/maintaining-dependencies.md b/graal-nodejs/doc/contributing/maintaining/maintaining-dependencies.md index 4cec1dce2c0..eb0e5960a7c 100644 --- a/graal-nodejs/doc/contributing/maintaining/maintaining-dependencies.md +++ b/graal-nodejs/doc/contributing/maintaining/maintaining-dependencies.md @@ -30,7 +30,7 @@ This a list of all the dependencies: * [uv][] * [uvwasi 0.0.19][] * [V8][] -* [zlib 1.2.13.1-motley-f5fd0ad][] +* [zlib 1.2.13.1-motley-fef5869][] Any code which meets one or more of these conditions should be managed as a dependency: @@ -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.2.13.1-motley-f5fd0ad +### zlib 1.2.13.1-motley-fef5869 The [zlib](https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/zlib) dependency lossless data-compression library, @@ -341,4 +341,4 @@ performance improvements not currently available in standard zlib. [uv]: #uv [uvwasi 0.0.19]: #uvwasi-0019 [v8]: #v8 -[zlib 1.2.13.1-motley-f5fd0ad]: #zlib-12131-motley-f5fd0ad +[zlib 1.2.13.1-motley-fef5869]: #zlib-12131-motley-fef5869