Skip to content

Commit 0522ac0

Browse files
deps: update zlib to 1.2.13.1-motley-fef5869
PR-URL: #50085 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent a0a5b75 commit 0522ac0

12 files changed

+126
-136
lines changed

deps/zlib/CMakeLists.txt

+53
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ check_include_file(stddef.h HAVE_STDDEF_H)
2424
option(ENABLE_SIMD_OPTIMIZATIONS "Enable all SIMD optimizations" OFF)
2525
option(ENABLE_SIMD_AVX512 "Enable SIMD AXV512 optimizations" OFF)
2626
option(USE_ZLIB_RABIN_KARP_HASH "Enable bitstream compatibility with canonical zlib" OFF)
27+
option(BUILD_UNITTESTS "Enable standalone unit tests build" OFF)
2728

2829
if (USE_ZLIB_RABIN_KARP_HASH)
2930
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).
244245
add_executable(zlib_bench contrib/bench/zlib_bench.cc)
245246
target_link_libraries(zlib_bench zlib)
246247

248+
#============================================================================
249+
# Unit Tests
250+
#============================================================================
251+
if (BUILD_UNITTESTS)
252+
include (ExternalProject)
253+
set_directory_properties(PROPERTIES EP_PREFIX ${CMAKE_BINARY_DIR}/third_party)
254+
ExternalProject_add(
255+
googletest
256+
GIT_REPOSITORY https://github.com/google/googletest.git
257+
GIT_TAG d1467f5813f4d363cfd11aba99c4e9fe47a85e99
258+
UPDATE_COMMAND ""
259+
INSTALL_COMMAND ""
260+
LOG_DOWNLOAD ON
261+
LOG_CONFIGURE ON
262+
LOG_BUILD ON
263+
)
264+
265+
# gtest includedir
266+
ExternalProject_Get_Property(googletest source_dir)
267+
set(GTEST_INCLUDE_DIRS
268+
${source_dir}/googletest/include
269+
${source_dir}/googletest/include/gtest
270+
)
271+
272+
# gtest library
273+
ExternalProject_Get_Property(googletest binary_dir)
274+
set(GTEST_LIBRARY_PATH ${binary_dir}/lib/${CMAKE_FIND_LIBRARY_PREFIXES}gtest.a)
275+
set(GTEST_LIBRARY gtest)
276+
add_library(${GTEST_LIBRARY} UNKNOWN IMPORTED)
277+
set_property(TARGET ${GTEST_LIBRARY} PROPERTY IMPORTED_LOCATION ${GTEST_LIBRARY_PATH})
278+
add_dependencies(${GTEST_LIBRARY} googletest)
279+
280+
set(UTEST_SRC
281+
${CMAKE_CURRENT_SOURCE_DIR}/contrib/tests/infcover.cc
282+
${CMAKE_CURRENT_SOURCE_DIR}/contrib/tests/infcover.h
283+
${CMAKE_CURRENT_SOURCE_DIR}/contrib/tests/utils_unittest.cc
284+
${CMAKE_CURRENT_SOURCE_DIR}/contrib/tests/standalone_test_runner.cc
285+
${CMAKE_CURRENT_SOURCE_DIR}/google/compression_utils_portable.cc
286+
)
287+
288+
add_compile_definitions(CMAKE_STANDALONE_UNITTESTS)
289+
290+
add_executable(zlib_unittests ${UTEST_SRC})
291+
target_include_directories(zlib_unittests PUBLIC ${GTEST_INCLUDE_DIRS})
292+
target_include_directories(zlib_unittests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/google)
293+
294+
target_link_libraries(zlib_unittests ${GTEST_LIBRARY})
295+
target_link_libraries(zlib_unittests zlib)
296+
# Needed by gtest
297+
target_link_libraries(zlib_unittests pthread)
298+
endif()
299+
247300
#============================================================================
248301
# Minigzip tool
249302
#============================================================================

deps/zlib/README.chromium

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Version: 1.2.13
55
CPEPrefix: cpe:/a:zlib:zlib:1.2.13
66
Security Critical: yes
77
Shipped: yes
8-
License: Custom license
8+
License: Zlib
99
License File: LICENSE
1010
License Android Compatible: yes
1111

deps/zlib/contrib/optimizations/inflate.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -1488,8 +1488,9 @@ int ZEXPORT inflateCopy(z_streamp dest, z_streamp source) {
14881488
if (copy == Z_NULL) return Z_MEM_ERROR;
14891489
window = Z_NULL;
14901490
if (state->window != Z_NULL) {
1491-
window = (unsigned char FAR *)
1492-
ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
1491+
window = (unsigned char FAR *)ZALLOC(
1492+
source, (1U << state->wbits) + CHUNKCOPY_CHUNK_SIZE,
1493+
sizeof(unsigned char));
14931494
if (window == Z_NULL) {
14941495
ZFREE(source, copy);
14951496
return Z_MEM_ERROR;

deps/zlib/contrib/optimizations/insert_string.h

+16-81
Original file line numberDiff line numberDiff line change
@@ -16,64 +16,7 @@
1616
#endif
1717
#endif
1818

19-
#include "cpu_features.h"
20-
21-
// clang-format off
22-
#if defined(CRC32_SIMD_SSE42_PCLMUL)
23-
#include <smmintrin.h> /* Required to make MSVC bot build pass. */
24-
25-
#if defined(__clang__) || defined(__GNUC__)
26-
#define TARGET_CPU_WITH_CRC __attribute__((target("sse4.2")))
27-
#else
28-
#define TARGET_CPU_WITH_CRC
29-
#endif
30-
31-
/* CRC32C uint32_t */
32-
#define _cpu_crc32c_hash_u32 _mm_crc32_u32
33-
34-
#elif defined(CRC32_ARMV8_CRC32)
35-
#if defined(__clang__)
36-
#define __crc32cw __builtin_arm_crc32cw
37-
#elif defined(__GNUC__)
38-
#define __crc32cw __builtin_aarch64_crc32cw
39-
#endif
40-
41-
#if defined(__aarch64__) && defined(__clang__)
42-
#define TARGET_CPU_WITH_CRC __attribute__((target("crc")))
43-
#elif defined(__aarch64__) && defined(__GNUC__)
44-
#define TARGET_CPU_WITH_CRC __attribute__((target("+crc")))
45-
#elif defined(__clang__) // !defined(__aarch64__)
46-
#define TARGET_CPU_WITH_CRC __attribute__((target("armv8-a,crc")))
47-
#endif // defined(__aarch64__)
48-
49-
/* CRC32C uint32_t */
50-
#define _cpu_crc32c_hash_u32 __crc32cw
51-
52-
#endif
53-
// clang-format on
54-
55-
#if defined(TARGET_CPU_WITH_CRC)
56-
57-
TARGET_CPU_WITH_CRC
58-
local INLINE Pos insert_string_simd(deflate_state* const s, const Pos str) {
59-
Pos ret;
60-
unsigned val, h = 0;
61-
62-
zmemcpy(&val, &s->window[str], sizeof(val));
63-
64-
if (s->level >= 6)
65-
val &= 0xFFFFFF;
66-
67-
/* Compute hash from the CRC32C of |val|. */
68-
h = _cpu_crc32c_hash_u32(h, val);
69-
70-
ret = s->head[h & s->hash_mask];
71-
s->head[h & s->hash_mask] = str;
72-
s->prev[str & s->w_mask] = ret;
73-
return ret;
74-
}
75-
76-
#endif // TARGET_CPU_WITH_CRC
19+
#include <stdint.h>
7720

7821
/**
7922
* 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) {
10750
* characters and the first MIN_MATCH bytes of str are valid (except for
10851
* the last MIN_MATCH-1 bytes of the input file).
10952
*/
110-
local INLINE Pos insert_string_c(deflate_state* const s, const Pos str) {
53+
local INLINE Pos insert_string(deflate_state* const s, const Pos str) {
11154
Pos ret;
112-
55+
/* insert_string dictionary insertion: ANZAC++ hasher
56+
* significantly improves data compression speed.
57+
*
58+
* Note: the generated compressed output is a valid DEFLATE stream, but will
59+
* differ from canonical zlib output.
60+
*/
61+
#if defined(USE_ZLIB_RABIN_KARP_ROLLING_HASH)
11362
UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH - 1)]);
63+
#else
64+
uint32_t value;
65+
// Validated for little endian archs (i.e. x86, Arm). YMMV for big endian.
66+
zmemcpy(&value, &s->window[str], sizeof(value));
67+
s->ins_h = ((value * 66521 + 66521) >> 16) & s->hash_mask;
68+
#endif
69+
11470
#ifdef FASTEST
11571
ret = s->head[s->ins_h];
11672
#else
@@ -121,25 +77,4 @@ local INLINE Pos insert_string_c(deflate_state* const s, const Pos str) {
12177
return ret;
12278
}
12379

124-
local INLINE Pos insert_string(deflate_state* const s, const Pos str) {
125-
/* insert_string_simd string dictionary insertion: SIMD crc32c symbol hasher
126-
* significantly improves data compression speed.
127-
*
128-
* Note: the generated compressed output is a valid DEFLATE stream, but will
129-
* differ from canonical zlib output.
130-
*/
131-
#if defined(USE_ZLIB_RABIN_KARP_ROLLING_HASH)
132-
/* So this build-time option can be used to disable the crc32c hash, and use
133-
* the Rabin-Karp hash instead.
134-
*/ /* FALLTHROUGH Rabin-Karp */
135-
#elif defined(TARGET_CPU_WITH_CRC) && defined(CRC32_SIMD_SSE42_PCLMUL)
136-
if (x86_cpu_enable_simd)
137-
return insert_string_simd(s, str);
138-
#elif defined(TARGET_CPU_WITH_CRC) && defined(CRC32_ARMV8_CRC32)
139-
if (arm_cpu_enable_crc32)
140-
return insert_string_simd(s, str);
141-
#endif
142-
return insert_string_c(s, str); /* Rabin-Karp */
143-
}
144-
14580
#endif /* INSERT_STRING_H */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright 2023 The Chromium Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the Chromium source repository LICENSE file.
4+
#include <gtest/gtest.h>
5+
6+
int main(int argc, char** argv) {
7+
::testing::InitGoogleTest(&argc, argv);
8+
return RUN_ALL_TESTS();
9+
}

deps/zlib/contrib/tests/utils_unittest.cc

+12-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@
77
#include <cstddef>
88
#include <vector>
99

10-
#include "base/files/file_path.h"
11-
#include "base/files/scoped_temp_dir.h"
1210
#include "compression_utils_portable.h"
1311
#include "gtest.h"
12+
13+
#if !defined(CMAKE_STANDALONE_UNITTESTS)
14+
#include "base/files/file_path.h"
15+
#include "base/files/scoped_temp_dir.h"
16+
1417
#include "third_party/zlib/contrib/minizip/unzip.h"
1518
#include "third_party/zlib/contrib/minizip/zip.h"
19+
#endif
20+
1621
#include "zlib.h"
1722

1823
void TestPayloads(size_t input_size, zlib_internal::WrapperType type) {
@@ -1020,6 +1025,9 @@ TEST(ZlibTest, DeflateZFixedCorruption) {
10201025
0);
10211026
}
10221027

1028+
// TODO(gustavoa): make these tests run standalone.
1029+
#ifndef CMAKE_STANDALONE_UNITTESTS
1030+
10231031
TEST(ZlibTest, ZipFilenameCommentSize) {
10241032
// Check that minizip rejects zip member filenames or comments longer than
10251033
// the zip format can represent.
@@ -1138,3 +1146,5 @@ TEST(ZlibTest, ZipExtraFieldSize) {
11381146
EXPECT_EQ(unzGoToNextFile(uzf), UNZ_END_OF_LIST_OF_FILE);
11391147
EXPECT_EQ(unzClose(uzf), UNZ_OK);
11401148
}
1149+
1150+
#endif

deps/zlib/deflate.c

+2-8
Original file line numberDiff line numberDiff line change
@@ -457,15 +457,9 @@ int ZEXPORT deflateInit2_(z_streamp strm, int level, int method,
457457
s->w_size = 1 << s->w_bits;
458458
s->w_mask = s->w_size - 1;
459459

460+
s->chromium_zlib_hash = 1;
461+
#if defined(USE_ZLIB_RABIN_KARP_ROLLING_HASH)
460462
s->chromium_zlib_hash = 0;
461-
#if !defined(USE_ZLIB_RABIN_KARP_ROLLING_HASH)
462-
#if defined(TARGET_CPU_WITH_CRC) && defined(CRC32_SIMD_SSE42_PCLMUL)
463-
if (x86_cpu_enable_simd)
464-
s->chromium_zlib_hash = 1;
465-
#elif defined(TARGET_CPU_WITH_CRC) && defined(CRC32_ARMV8_CRC32)
466-
if (arm_cpu_enable_crc32)
467-
s->chromium_zlib_hash = 1;
468-
#endif
469463
#endif
470464

471465
s->hash_bits = memLevel + 7;

deps/zlib/google/DEPS

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ include_rules = [
22
'+base',
33
'+build',
44
'+testing',
5-
"+third_party/zlib/zlib.h",
5+
'+third_party/icu/source/i18n/unicode',
6+
'+third_party/zlib/zlib.h',
67
]

deps/zlib/google/zip_internal.cc

+7-6
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,13 @@ zip_fileinfo TimeToZipFileInfo(const base::Time& file_time) {
260260
// It assumes that dates below 1980 are in the double digit format.
261261
// Hence the fail safe option is to leave the date unset. Some programs
262262
// might show the unset date as 1980-0-0 which is invalid.
263-
zip_info.tmz_date.tm_year = file_time_parts.year;
264-
zip_info.tmz_date.tm_mon = file_time_parts.month - 1;
265-
zip_info.tmz_date.tm_mday = file_time_parts.day_of_month;
266-
zip_info.tmz_date.tm_hour = file_time_parts.hour;
267-
zip_info.tmz_date.tm_min = file_time_parts.minute;
268-
zip_info.tmz_date.tm_sec = file_time_parts.second;
263+
zip_info.tmz_date = {
264+
.tm_sec = static_cast<uInt>(file_time_parts.second),
265+
.tm_min = static_cast<uInt>(file_time_parts.minute),
266+
.tm_hour = static_cast<uInt>(file_time_parts.hour),
267+
.tm_mday = static_cast<uInt>(file_time_parts.day_of_month),
268+
.tm_mon = static_cast<uInt>(file_time_parts.month - 1),
269+
.tm_year = static_cast<uInt>(file_time_parts.year)};
269270
}
270271

271272
return zip_info;

deps/zlib/google/zip_reader.cc

+8-8
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,14 @@ bool ZipReader::OpenEntry() {
246246

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

258258
if (!base::Time::FromUTCExploded(exploded_time, &entry_.last_modified))
259259
entry_.last_modified = base::Time::UnixEpoch();

deps/zlib/google/zip_reader_unittest.cc

+10-24
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "base/files/scoped_temp_dir.h"
2020
#include "base/functional/bind.h"
2121
#include "base/hash/md5.h"
22+
#include "base/i18n/time_formatting.h"
2223
#include "base/path_service.h"
2324
#include "base/run_loop.h"
2425
#include "base/strings/string_piece.h"
@@ -31,6 +32,7 @@
3132
#include "testing/gmock/include/gmock/gmock.h"
3233
#include "testing/gtest/include/gtest/gtest.h"
3334
#include "testing/platform_test.h"
35+
#include "third_party/icu/source/i18n/unicode/timezone.h"
3436
#include "third_party/zlib/google/zip_internal.h"
3537

3638
using ::testing::_;
@@ -288,18 +290,10 @@ TEST_F(ZipReaderTest, RegularFile) {
288290

289291
EXPECT_EQ(target_path, entry->path);
290292
EXPECT_EQ(13527, entry->original_size);
291-
292-
// The expected time stamp: 2009-05-29 06:22:20
293-
base::Time::Exploded exploded = {}; // Zero-clear.
294-
entry->last_modified.UTCExplode(&exploded);
295-
EXPECT_EQ(2009, exploded.year);
296-
EXPECT_EQ(5, exploded.month);
297-
EXPECT_EQ(29, exploded.day_of_month);
298-
EXPECT_EQ(6, exploded.hour);
299-
EXPECT_EQ(22, exploded.minute);
300-
EXPECT_EQ(20, exploded.second);
301-
EXPECT_EQ(0, exploded.millisecond);
302-
293+
EXPECT_EQ("2009-05-29 06:22:20.000",
294+
base::UnlocalizedTimeFormatWithPattern(entry->last_modified,
295+
"y-MM-dd HH:mm:ss.SSS",
296+
icu::TimeZone::getGMT()));
303297
EXPECT_FALSE(entry->is_unsafe);
304298
EXPECT_FALSE(entry->is_directory);
305299
}
@@ -396,18 +390,10 @@ TEST_F(ZipReaderTest, Directory) {
396390
EXPECT_EQ(target_path, entry->path);
397391
// The directory size should be zero.
398392
EXPECT_EQ(0, entry->original_size);
399-
400-
// The expected time stamp: 2009-05-31 15:49:52
401-
base::Time::Exploded exploded = {}; // Zero-clear.
402-
entry->last_modified.UTCExplode(&exploded);
403-
EXPECT_EQ(2009, exploded.year);
404-
EXPECT_EQ(5, exploded.month);
405-
EXPECT_EQ(31, exploded.day_of_month);
406-
EXPECT_EQ(15, exploded.hour);
407-
EXPECT_EQ(49, exploded.minute);
408-
EXPECT_EQ(52, exploded.second);
409-
EXPECT_EQ(0, exploded.millisecond);
410-
393+
EXPECT_EQ("2009-05-31 15:49:52.000",
394+
base::UnlocalizedTimeFormatWithPattern(entry->last_modified,
395+
"y-MM-dd HH:mm:ss.SSS",
396+
icu::TimeZone::getGMT()));
411397
EXPECT_FALSE(entry->is_unsafe);
412398
EXPECT_TRUE(entry->is_directory);
413399
}

0 commit comments

Comments
 (0)