Skip to content

Commit dc10238

Browse files
nodejs-github-bottargos
authored andcommitted
deps: update zlib to 1.3.1-470d3a2
PR-URL: #58628 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent 4347ce3 commit dc10238

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+890
-324
lines changed

deps/zlib/BUILD.gn

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,25 +173,31 @@ if (use_arm_neon_optimizations) {
173173
}
174174
}
175175

176-
config("zlib_inflate_chunk_simd_config") {
176+
config("zlib_data_chunk_simd_config") {
177177
if (use_x86_x64_optimizations) {
178178
defines = [ "INFLATE_CHUNK_SIMD_SSE2" ]
179179

180180
if (current_cpu == "x64") {
181-
defines += [ "INFLATE_CHUNK_READ_64LE" ]
181+
defines += [
182+
"INFLATE_CHUNK_READ_64LE",
183+
"DEFLATE_CHUNK_WRITE_64LE",
184+
]
182185
}
183186
}
184187

185188
if (use_arm_neon_optimizations) {
186189
defines = [ "INFLATE_CHUNK_SIMD_NEON" ]
187190

188191
if (current_cpu == "arm64") {
189-
defines += [ "INFLATE_CHUNK_READ_64LE" ]
192+
defines += [
193+
"INFLATE_CHUNK_READ_64LE",
194+
"DEFLATE_CHUNK_WRITE_64LE",
195+
]
190196
}
191197
}
192198
}
193199

194-
source_set("zlib_inflate_chunk_simd") {
200+
source_set("zlib_data_chunk_simd") {
195201
visibility = [ ":*" ]
196202

197203
if (use_x86_x64_optimizations || use_arm_neon_optimizations) {
@@ -213,7 +219,7 @@ source_set("zlib_inflate_chunk_simd") {
213219
configs += [ "//build/config/compiler:no_chromium_code" ]
214220
configs += [ ":zlib_warnings" ]
215221

216-
public_configs = [ ":zlib_inflate_chunk_simd_config" ]
222+
public_configs = [ ":zlib_data_chunk_simd_config" ]
217223

218224
public_deps = [ ":zlib_common_headers" ]
219225
}
@@ -336,7 +342,7 @@ component("zlib") {
336342
if (use_x86_x64_optimizations || use_arm_neon_optimizations) {
337343
deps += [
338344
":zlib_adler32_simd",
339-
":zlib_inflate_chunk_simd",
345+
":zlib_data_chunk_simd",
340346
":zlib_slide_hash_simd",
341347
]
342348

deps/zlib/CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON)
33

44
project(zlib C)
55

6-
set(VERSION "1.3.0.1")
6+
set(VERSION "1.3.1")
77

88
set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables")
99
set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries")
@@ -47,6 +47,7 @@ if (ENABLE_SIMD_OPTIMIZATIONS)
4747
add_definitions(-DINFLATE_CHUNK_SIMD_SSE2)
4848
add_definitions(-DADLER32_SIMD_SSSE3)
4949
add_definitions(-DINFLATE_CHUNK_READ_64LE)
50+
add_definitions(-DDEFLATE_CHUNK_WRITE_64LE)
5051
add_definitions(-DCRC32_SIMD_SSE42_PCLMUL)
5152
if (ENABLE_SIMD_AVX512)
5253
add_definitions(-DCRC32_SIMD_AVX512_PCLMUL)
@@ -64,6 +65,7 @@ if (ENABLE_SIMD_OPTIMIZATIONS)
6465
add_definitions(-DINFLATE_CHUNK_SIMD_NEON)
6566
add_definitions(-DADLER32_SIMD_NEON)
6667
add_definitions(-DINFLATE_CHUNK_READ_64LE)
68+
add_definitions(-DDEFLATE_CHUNK_WRITE_64LE)
6769
add_definitions(-DCRC32_ARMV8_CRC32)
6870
add_definitions(-DDEFLATE_SLIDE_HASH_NEON)
6971
# Required by CPU features detection code.
@@ -83,10 +85,13 @@ if (ENABLE_SIMD_OPTIMIZATIONS)
8385
add_definitions(-DDEFLATE_SLIDE_HASH_RVV)
8486
add_definitions(-DADLER32_SIMD_RVV)
8587

86-
# TODO(cavalcantii): add remaining flags as we port optimizations to RVV.
8788
# chunk_copy is required for READ64 and unconditional decode of literals.
8889
add_definitions(-DINFLATE_CHUNK_GENERIC)
8990
add_definitions(-DINFLATE_CHUNK_READ_64LE)
91+
add_definitions(-DDEFLATE_CHUNK_WRITE_64LE)
92+
93+
# TODO(cavalcantii): only missing optimization is SLIDE_HASH, got port it
94+
# to RISCV.
9095

9196
# Tested with clang-17, unaligned loads are required by read64 & chunk_copy.
9297
# TODO(cavalcantii): replace internal clang flags for -munaligned-access
@@ -267,7 +272,9 @@ if(MINGW)
267272
endif(MINGW)
268273

269274
add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
275+
target_include_directories(zlib PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
270276
add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
277+
target_include_directories(zlibstatic PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
271278
set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL)
272279
set_target_properties(zlib PROPERTIES SOVERSION 1)
273280

deps/zlib/OWNERS

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
3-
cblume@chromium.org
4-
2+
hans@chromium.org
3+
[email protected] #{LAST_RESORT_SUGGESTION}

deps/zlib/README.chromium

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Name: zlib
22
Short Name: zlib
33
URL: http://zlib.net/
4-
Version: 1.3.0.1
5-
Revision: ac8f12c97d1afd9bafa9c710f827d40a407d3266
6-
CPEPrefix: cpe:/a:zlib:zlib:1.3.0.1
4+
Version: 1.3.1
5+
Revision: 51b7f2abdade71cd9bb0e7a373ef2610ec6f9daf
6+
CPEPrefix: cpe:/a:zlib:zlib:1.3.1
77
Security Critical: yes
88
Shipped: yes
99
License: Zlib
@@ -21,14 +21,17 @@ also implements the zlib (RFC 1950) and gzip (RFC 1952) wrapper formats.
2121
Local Modifications:
2222
- Only source code from the zlib distribution used to build the zlib and
2323
minizip libraries are present. Many other files have been omitted. Only *.c
24-
and *.h files from the upstream root directory and contrib/minizip were
25-
imported.
24+
and *.h files from the upstream root directory, contrib/minizip and
25+
examples/zpipe.c were imported.
26+
- The files named '*simd*' are original x86/Arm/RISC-V specific optimizations.
2627
- The contents of the google directory are original Chromium-specific
2728
additions.
29+
- The contents of the 'contrib' of directory are either Chromium-specific
30+
additions or heavily patched zlib files (e.g. inffast_chunk*).
2831
- Added chromeconf.h
2932
- Plus the changes in 'patches' folder.
3033
- Code in contrib/ other than contrib/minizip was added to match zlib's
3134
contributor layout.
32-
- In sync with 1.2.13 official release
35+
- In sync with 1.3.1 official release
3336
- ZIP reader modified to allow for progress callbacks during extraction.
3437
- ZIP reader modified to add detection of AES encrypted content.

deps/zlib/contrib/minizip/README.chromium

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,8 @@ Local Modifications:
3434
https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT section 4.6.9.
3535
(see crrev.com/1002476)
3636
0016-minizip-parse-unicode-path-extra-field.patch
37+
38+
- Added support for zip64 archives that have extra bytes on front (for example,
39+
large CRX files).
40+
0018-support-prefixed-zip64.patch
41+

deps/zlib/contrib/minizip/unzip.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,46 @@ local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib
482482
if (uL != 1)
483483
return CENTRALDIRINVALID;
484484

485+
/* If bytes are pre-pended to the archive, relativeOffset must be advanced
486+
by that many bytes. The central dir must exist between the specified
487+
relativeOffset and uPosFound. */
488+
if (relativeOffset > uPosFound)
489+
return CENTRALDIRINVALID;
490+
const int BUFSIZE = 1024 * 4;
491+
buf = (unsigned char*)ALLOC(BUFSIZE);
492+
if (buf==NULL)
493+
return CENTRALDIRINVALID;
494+
// Zip64 EOCDR is at least 48 bytes long.
495+
while (uPosFound - relativeOffset >= 48) {
496+
int found = 0;
497+
uLong uReadSize = uPosFound - relativeOffset;
498+
if (uReadSize > BUFSIZE) {
499+
uReadSize = BUFSIZE;
500+
}
501+
if (ZSEEK64(*pzlib_filefunc_def, filestream, relativeOffset, ZLIB_FILEFUNC_SEEK_SET) != 0) {
502+
break;
503+
}
504+
if (ZREAD64(*pzlib_filefunc_def, filestream, buf, uReadSize) != uReadSize) {
505+
break;
506+
}
507+
for (int i = 0; i < uReadSize - 3; ++i) {
508+
// Looking for 0x06064b50, the Zip64 EOCDR signature.
509+
if (buf[i] == 0x50 && buf[i + 1] == 0x4b &&
510+
buf[i + 2] == 0x06 && buf[i + 3] == 0x06)
511+
{
512+
relativeOffset += i;
513+
found = 1;
514+
break;
515+
}
516+
}
517+
if (found) {
518+
break;
519+
}
520+
// Re-read the last 3 bytes, in case they're the front of the signature.
521+
relativeOffset += uReadSize - 3;
522+
}
523+
free(buf);
524+
485525
/* Goto end of central directory record */
486526
if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0)
487527
return CENTRALDIRINVALID;
@@ -1005,6 +1045,8 @@ local int unz64local_GetCurrentFileInfoInternal(unzFile file,
10051045
{
10061046
uLong uSizeRead;
10071047

1048+
file_info.size_filename = fileNameSize;
1049+
10081050
if (fileNameSize < fileNameBufferSize)
10091051
{
10101052
*(szFileName + fileNameSize) = '\0';

deps/zlib/contrib/tests/fuzzers/BUILD.gn

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,9 @@ fuzzer_test("zlib_deflate_fuzzer") {
4343
sources = [ "deflate_fuzzer.cc" ]
4444
deps = [ "../../../:zlib" ]
4545
}
46+
47+
fuzzer_test("minizip_unzip_fuzzer") {
48+
sources = [ "minizip_unzip_fuzzer.cc" ]
49+
deps = [ "../../../:minizip" ]
50+
include_dirs = [ "//third_party/zlib/contrib/minizip" ]
51+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// Copyright 2025 The Chromium Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include <algorithm>
6+
#include <cstdint>
7+
#include <cstring>
8+
#include <vector>
9+
10+
#include "unzip.h"
11+
12+
// Fuzzer builds often have NDEBUG set, so roll our own assert macro.
13+
#define ASSERT(cond) \
14+
do { \
15+
if (!(cond)) { \
16+
fprintf(stderr, "%s:%d Assert failed: %s\n", __FILE__, __LINE__, #cond); \
17+
exit(1); \
18+
} \
19+
} while (0)
20+
21+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
22+
// Mock read-only filesystem with only one file, file_data. In the calls
23+
// below, 'opaque' points to file_data, and 'strm' points to the file's seek
24+
// position, which is heap allocated so that failing to "close" it triggers a
25+
// leak error.
26+
std::vector<uint8_t> file_data(data, data + size);
27+
zlib_filefunc64_def file_func = {
28+
.zopen64_file = [](void* opaque, const void* filename,
29+
int mode) -> void* {
30+
ASSERT(mode == (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_EXISTING));
31+
return new size_t(0);
32+
},
33+
.zread_file = [](void* opaque, void* strm, void* buf,
34+
uLong size) -> uLong {
35+
std::vector<uint8_t>* vec = static_cast<std::vector<uint8_t>*>(opaque);
36+
size_t* pos = static_cast<size_t*>(strm);
37+
if (*pos >= vec->size()) {
38+
return 0;
39+
}
40+
size = std::min(static_cast<size_t>(size), vec->size() - *pos);
41+
memcpy(buf, vec->data() + *pos, size);
42+
(*pos) += size;
43+
return size;
44+
},
45+
.zwrite_file = [](void*, void*, const void*, uLong) -> uLong {
46+
ASSERT(0 && "Writing is not supported.");
47+
return 0;
48+
},
49+
.ztell64_file = [](void*, void* strm) -> ZPOS64_T {
50+
return *static_cast<size_t*>(strm);
51+
},
52+
.zseek64_file = [](void* opaque, void* strm, ZPOS64_T offset,
53+
int origin) -> long {
54+
std::vector<uint8_t>* vec = static_cast<std::vector<uint8_t>*>(opaque);
55+
size_t* pos = static_cast<size_t*>(strm);
56+
switch (origin) {
57+
case ZLIB_FILEFUNC_SEEK_SET:
58+
*pos = offset;
59+
break;
60+
case ZLIB_FILEFUNC_SEEK_CUR:
61+
*pos = *pos + offset;
62+
break;
63+
case ZLIB_FILEFUNC_SEEK_END:
64+
*pos = vec->size() + offset;
65+
break;
66+
default:
67+
ASSERT(0 && "Invalid origin");
68+
}
69+
return 0;
70+
},
71+
.zclose_file = [](void*, void* strm) -> int {
72+
delete static_cast<size_t*>(strm);
73+
return 0;
74+
},
75+
.zerror_file = [](void*, void*) -> int { return 0; },
76+
.opaque = &file_data};
77+
78+
unzFile uzf = unzOpen2_64("foo.zip", &file_func);
79+
if (uzf == NULL) {
80+
return 0;
81+
}
82+
83+
while (true) {
84+
unz_file_info64 info = {0};
85+
86+
// TODO: Pass nullptrs and different buffer sizes to cover more code.
87+
char filename[UINT16_MAX + 1]; // +1 for the null terminator.
88+
char extra[UINT16_MAX]; // No null terminator.
89+
char comment[UINT16_MAX + 1]; // +1 for the null terminator.
90+
91+
if (unzGetCurrentFileInfo64(uzf, &info, filename, sizeof(filename), extra,
92+
sizeof(extra), comment, sizeof(comment)) == UNZ_OK) {
93+
ASSERT(info.size_filename <= UINT16_MAX);
94+
ASSERT(info.size_file_extra <= UINT16_MAX);
95+
ASSERT(info.size_file_comment <= UINT16_MAX);
96+
97+
ASSERT(filename[info.size_filename] == '\0');
98+
ASSERT(comment[info.size_file_comment] == '\0');
99+
}
100+
101+
if (unzOpenCurrentFile(uzf) == UNZ_OK) {
102+
while (true) {
103+
char buffer[4096];
104+
int num_read = unzReadCurrentFile(uzf, buffer, sizeof(buffer));
105+
if (num_read <= 0) {
106+
break;
107+
}
108+
}
109+
unzCloseCurrentFile(uzf);
110+
}
111+
112+
if (unzGoToNextFile(uzf) != UNZ_OK) {
113+
break;
114+
}
115+
}
116+
117+
unzClose(uzf);
118+
return 0;
119+
}

0 commit comments

Comments
 (0)