Skip to content

Commit 9f2cfd4

Browse files
deps: update zlib to 1.3.1-a1f2fe2
1 parent f497881 commit 9f2cfd4

Some content is hidden

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

42 files changed

+805
-309
lines changed

deps/zlib/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
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")
@@ -267,7 +267,9 @@ if(MINGW)
267267
endif(MINGW)
268268

269269
add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
270+
target_include_directories(zlib PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
270271
add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
272+
target_include_directories(zlibstatic PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
271273
set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL)
272274
set_target_properties(zlib PROPERTIES SOVERSION 1)
273275

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+
}

deps/zlib/deflate.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* deflate.c -- compress data using the deflation algorithm
2-
* Copyright (C) 1995-2023 Jean-loup Gailly and Mark Adler
2+
* Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler
33
* For conditions of distribution and use, see copyright notice in zlib.h
44
*/
55

@@ -69,7 +69,7 @@
6969
#endif
7070

7171
const char deflate_copyright[] =
72-
" deflate 1.3.0.1 Copyright 1995-2023 Jean-loup Gailly and Mark Adler ";
72+
" deflate 1.3.1 Copyright 1995-2024 Jean-loup Gailly and Mark Adler ";
7373
/*
7474
If you use the zlib library in a product, an acknowledgment is welcome
7575
in the documentation of your product. If for some reason you cannot
@@ -1663,13 +1663,21 @@ local uInt longest_match(deflate_state *s, IPos cur_match) {
16631663
*/
16641664
local void check_match(deflate_state *s, IPos start, IPos match, int length) {
16651665
/* check that the match is indeed a match */
1666-
if (zmemcmp(s->window + match,
1667-
s->window + start, length) != EQUAL) {
1668-
fprintf(stderr, " start %u, match %u, length %d\n",
1669-
start, match, length);
1666+
Bytef *back = s->window + (int)match, *here = s->window + start;
1667+
IPos len = length;
1668+
if (match == (IPos)-1) {
1669+
/* match starts one byte before the current window -- just compare the
1670+
subsequent length-1 bytes */
1671+
back++;
1672+
here++;
1673+
len--;
1674+
}
1675+
if (zmemcmp(back, here, len) != EQUAL) {
1676+
fprintf(stderr, " start %u, match %d, length %d\n",
1677+
start, (int)match, length);
16701678
do {
1671-
fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
1672-
} while (--length != 0);
1679+
fprintf(stderr, "(%02x %02x)", *back++, *here++);
1680+
} while (--len != 0);
16731681
z_error("invalid match");
16741682
}
16751683
if (z_verbose > 1) {
@@ -2106,13 +2114,7 @@ local block_state deflate_slow(deflate_state *s, int flush) {
21062114
uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
21072115
/* Do not insert strings in hash table beyond this. */
21082116

2109-
if (s->prev_match == -1) {
2110-
/* The window has slid one byte past the previous match,
2111-
* so the first byte cannot be compared. */
2112-
check_match(s, s->strstart, s->prev_match + 1, s->prev_length - 1);
2113-
} else {
2114-
check_match(s, s->strstart - 1, s->prev_match, s->prev_length);
2115-
}
2117+
check_match(s, s->strstart - 1, s->prev_match, s->prev_length);
21162118

21172119
_tr_tally_dist(s, s->strstart - 1 - s->prev_match,
21182120
s->prev_length - MIN_MATCH, bflush);

deps/zlib/deflate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* deflate.h -- internal compression state
2-
* Copyright (C) 1995-2018 Jean-loup Gailly
2+
* Copyright (C) 1995-2024 Jean-loup Gailly
33
* For conditions of distribution and use, see copyright notice in zlib.h
44
*/
55

deps/zlib/google/OWNERS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ [email protected]
22

33
# compression_utils*
44
5-
65

0 commit comments

Comments
 (0)