Skip to content

Commit 3a30bca

Browse files
deps: update zlib to 1.3.2.1-motley-456ae73
PR-URL: #66330 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 914c1c8 commit 3a30bca

4 files changed

Lines changed: 76 additions & 13 deletions

File tree

‎deps/zlib/BUILD.gn‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,6 @@ component("zlib") {
375375
# Must be after no_chromium_code for warning flags to be ordered correctly.
376376
":zlib_warnings",
377377
]
378-
379-
allow_circular_includes_from = deps
380378
}
381379

382380
config("minizip_warnings") {

‎deps/zlib/contrib/optimizations/inffast_chunk.c‎

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,28 +132,35 @@ void ZLIB_INTERNAL inflate_fast_chunk_(z_streamp strm, unsigned start) {
132132
} while (0)
133133
#endif
134134

135+
#ifdef INFLATE_CHUNK_READ_64LE
136+
REFILL();
137+
#endif
138+
135139
/* decode literals and length/distances until end-of-block or not enough
136140
input data or output space */
137141
do {
138-
#ifdef INFLATE_CHUNK_READ_64LE
139-
REFILL();
140-
#else
142+
#ifndef INFLATE_CHUNK_READ_64LE
141143
if (bits < 15) {
142144
hold += (unsigned long)(*in++) << bits;
143145
bits += 8;
144146
hold += (unsigned long)(*in++) << bits;
145147
bits += 8;
146148
}
147149
#endif
150+
/* Worst case: previous iteration had 3 literals (56 - 20 (lits) - 15 (lit) = 21 bits)
151+
or a match (56 - 15 (dist) - 13 (extra) = 28 bits), leaving bits >= lenbits (<= 10). */
152+
Assert(bits >= state->lenbits, "inflate_fast: short lit/len index");
148153
here = lcode + (hold & lmask);
149154
#ifdef INFLATE_CHUNK_READ_64LE
150-
if (here->op == 0) { /* literal */
155+
REFILL();
156+
if (here->op == 0) { /* literal */
151157
Tracevv((stderr, here->val >= 0x20 && here->val < 0x7f ?
152158
"inflate: literal '%c'\n" :
153159
"inflate: literal 0x%02x\n", here->val));
154160
*out++ = (unsigned char)(here->val);
155161
hold >>= here->bits;
156162
bits -= here->bits;
163+
Assert(bits >= state->lenbits, "inflate_fast: short 2nd lit/len index");
157164
here = lcode + (hold & lmask);
158165
if (here->op == 0) { /* literal */
159166
Tracevv((stderr, here->val >= 0x20 && here->val < 0x7f ?
@@ -162,6 +169,7 @@ void ZLIB_INTERNAL inflate_fast_chunk_(z_streamp strm, unsigned start) {
162169
*out++ = (unsigned char)(here->val);
163170
hold >>= here->bits;
164171
bits -= here->bits;
172+
Assert(bits >= state->lenbits, "inflate_fast: short 3rd lit/len index");
165173
here = lcode + (hold & lmask);
166174
}
167175
}
@@ -187,6 +195,7 @@ void ZLIB_INTERNAL inflate_fast_chunk_(z_streamp strm, unsigned start) {
187195
bits += 8;
188196
}
189197
#endif
198+
Assert(bits >= op, "inflate_fast: short length extra bits");
190199
len += (unsigned)hold & ((1U << op) - 1);
191200
hold >>= op;
192201
bits -= op;
@@ -200,7 +209,14 @@ void ZLIB_INTERNAL inflate_fast_chunk_(z_streamp strm, unsigned start) {
200209
bits += 8;
201210
}
202211
#endif
212+
/* Worst case: 56 - 20 (lits) - 15 (len) - 5 (extra) = 16 bits remain for distbits <= 9. */
213+
Assert(bits >= state->distbits, "inflate_fast: short dist index");
203214
here = dcode + (hold & dmask);
215+
#ifdef INFLATE_CHUNK_READ_64LE
216+
/* Refill after the table load so the two can overlap, and so the
217+
distance code and its extra bits start from a full 56 bits. */
218+
REFILL();
219+
#endif
204220
dodist:
205221
op = (unsigned)(here->bits);
206222
hold >>= op;
@@ -209,20 +225,17 @@ void ZLIB_INTERNAL inflate_fast_chunk_(z_streamp strm, unsigned start) {
209225
if (op & 16) { /* distance base */
210226
dist = (unsigned)(here->val);
211227
op &= 15; /* number of extra bits */
212-
/* we have two fast-path loads: 10+10 + 15+5 + 15 = 55,
213-
but we may need to refill here in the worst case */
228+
#ifndef INFLATE_CHUNK_READ_64LE
214229
if (bits < op) {
215-
#ifdef INFLATE_CHUNK_READ_64LE
216-
REFILL();
217-
#else
218230
hold += (unsigned long)(*in++) << bits;
219231
bits += 8;
220232
if (bits < op) {
221233
hold += (unsigned long)(*in++) << bits;
222234
bits += 8;
223235
}
224-
#endif
225236
}
237+
#endif
238+
Assert(bits >= op, "inflate_fast: short distance extra bits");
226239
dist += (unsigned)hold & ((1U << op) - 1);
227240
#ifdef INFLATE_STRICT
228241
if (dist > dmax) {
@@ -313,6 +326,7 @@ void ZLIB_INTERNAL inflate_fast_chunk_(z_streamp strm, unsigned start) {
313326
}
314327
}
315328
else if ((op & 64) == 0) { /* 2nd level distance code */
329+
Assert(bits >= op, "inflate_fast: short 2nd level dist index");
316330
here = dcode + here->val + (hold & ((1U << op) - 1));
317331
goto dodist;
318332
}
@@ -323,6 +337,7 @@ void ZLIB_INTERNAL inflate_fast_chunk_(z_streamp strm, unsigned start) {
323337
}
324338
}
325339
else if ((op & 64) == 0) { /* 2nd level length code */
340+
Assert(bits >= op, "inflate_fast: short 2nd level lit/len index");
326341
here = lcode + here->val + (hold & ((1U << op) - 1));
327342
goto dolen;
328343
}

‎deps/zlib/contrib/tests/utils_unittest.cc‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,55 @@ TEST(ZlibTest, InflateCopySIGILLReproduction) {
12481248
}
12491249
}
12501250

1251+
TEST(ZlibTest, InflateChunkRefillDistanceBitBudget) {
1252+
// Tests the edge case where one fast-loop iteration uses 10 + 10 + 15 + 5 +
1253+
// 15 = 55 of the 56 bits a refill. There should be sufficient bits for the
1254+
// next iteration.
1255+
static const uint8_t kCompressed[] = {
1256+
0xcd, 0xef, 0x01, 0x82, 0x24, 0x49, 0x92, 0x24, 0x49, 0x22, 0xb1, 0xa8,
1257+
0x79, 0xf5, 0xec, 0x2f, 0x33, 0xf3, 0x17, 0xf7, 0x7a, 0xf8, 0xc6, 0x1d,
1258+
0x20, 0xb1, 0xa8, 0x79, 0x64, 0xf5, 0xec, 0xfd, 0xf3, 0xef, 0xff, 0x1f,
1259+
0xfc, 0xff, 0xfe, 0xfd, 0xe7, 0xdf, 0xff, 0x3f, 0xf8, 0xff, 0xfd, 0xfb,
1260+
0xcf, 0xbf, 0xff, 0x7f, 0xf0, 0xff, 0xfb, 0x17};
1261+
std::vector<uint8_t> output(402 + 512);
1262+
z_stream stream = {};
1263+
stream.next_in = const_cast<uint8_t*>(kCompressed);
1264+
stream.avail_in = sizeof(kCompressed);
1265+
stream.next_out = output.data();
1266+
stream.avail_out = output.size();
1267+
1268+
ASSERT_EQ(Z_OK, inflateInit2(&stream, -MAX_WBITS));
1269+
EXPECT_EQ(Z_STREAM_END, inflate(&stream, Z_FINISH));
1270+
EXPECT_EQ(402u, stream.total_out);
1271+
EXPECT_EQ(Z_OK, inflateEnd(&stream));
1272+
EXPECT_EQ('b', output[133]); // Decodes as 'a' if the refill is not reached.
1273+
}
1274+
1275+
TEST(ZlibTest, InflateChunkRefillLiteralBitBudget) {
1276+
// Test an edge case where an iteration ends at a literal. and returns to the
1277+
// top of the inflate loop.
1278+
static const uint8_t kCompressed[] = {
1279+
0x05, 0xe0, 0x81, 0x81, 0x04, 0x49, 0x92, 0x24, 0x49, 0xb2, 0xa8, 0x79,
1280+
0x64, 0xcf, 0x1e, 0x96, 0x55, 0x05, 0xc5, 0x3f, 0xf4, 0x44, 0xff, 0xfe,
1281+
0xf7, 0xcf, 0x3f, 0xff, 0xbf, 0x7f, 0xff, 0xfb, 0xe7, 0x9f, 0xff, 0xdf,
1282+
0xbf, 0xff, 0xfd, 0xf3, 0xcf, 0xff, 0xef, 0xdf, 0xff, 0xfe, 0xf9, 0xe7,
1283+
0xff, 0xf7, 0xef, 0x7f, 0xff, 0xfc, 0xf3, 0xff, 0xfb, 0xf7, 0xbf, 0x7f,
1284+
0xfe, 0xf9, 0xff, 0x01};
1285+
std::vector<uint8_t> output(30 + 512);
1286+
z_stream stream = {};
1287+
stream.next_in = const_cast<uint8_t*>(kCompressed);
1288+
stream.avail_in = sizeof(kCompressed);
1289+
stream.next_out = output.data();
1290+
stream.avail_out = output.size();
1291+
1292+
ASSERT_EQ(Z_OK, inflateInit2(&stream, -MAX_WBITS));
1293+
EXPECT_EQ(Z_STREAM_END, inflate(&stream, Z_FINISH));
1294+
EXPECT_EQ(30u, stream.total_out);
1295+
EXPECT_EQ(Z_OK, inflateEnd(&stream));
1296+
// Decodes as 'a' if the accumulator runs short before the next lookup.
1297+
EXPECT_EQ('b', output[5]);
1298+
}
1299+
12511300
// TODO(gustavoa): make these tests run standalone.
12521301
#ifndef CMAKE_STANDALONE_UNITTESTS
12531302

@@ -1513,3 +1562,4 @@ TEST(ZlibTest, Compare256ReachesMaxMatch) {
15131562
}
15141563

15151564
#endif
1565+

‎src/zlib_version.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
// Refer to tools/dep_updaters/update-zlib.sh
33
#ifndef SRC_ZLIB_VERSION_H_
44
#define SRC_ZLIB_VERSION_H_
5-
#define ZLIB_VERSION "1.3.2.1-motley-285e94b"
5+
#define ZLIB_VERSION "1.3.2.1-motley-456ae73"
66
#endif // SRC_ZLIB_VERSION_H_

0 commit comments

Comments
 (0)