Skip to content

Commit a8bc7ac

Browse files
committed
Import some Chromium Zlib changes
1 parent d8fac40 commit a8bc7ac

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

third_party/zlib/crc_folding.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ ZLIB_INTERNAL void crc_fold_copy(deflate_state *const s,
406406
}
407407
#endif
408408

409-
_mm_storeu_si128((__m128i *)dst, xmm_crc_part);
409+
memcpy(dst, src, len); /* TODO: Possibly generate more efficient code. */
410410
partial_fold(s, len, &xmm_crc0, &xmm_crc1, &xmm_crc2, &xmm_crc3,
411411
&xmm_crc_part);
412412
done:

third_party/zlib/deflate.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ int ZEXPORT deflateInit(strm, level)
229229
/* To do: ignore strm->next_in if we use it as window */
230230
}
231231

232+
#define WINDOW_PADDING 8
233+
232234
/* ========================================================================= */
233235
int ZEXPORT deflateInit2(strm, level, method, windowBits, memLevel, strategy)
234236
z_streamp strm;
@@ -238,7 +240,6 @@ int ZEXPORT deflateInit2(strm, level, method, windowBits, memLevel, strategy)
238240
int memLevel;
239241
int strategy;
240242
{
241-
unsigned window_padding = 8;
242243
deflate_state *s;
243244
int wrap = 1;
244245

@@ -325,12 +326,12 @@ int ZEXPORT deflateInit2(strm, level, method, windowBits, memLevel, strategy)
325326
s->hash_shift = ((s->hash_bits + MIN_MATCH-1) / MIN_MATCH);
326327

327328
s->window = (Bytef *) ZALLOC(strm,
328-
s->w_size + window_padding,
329+
s->w_size + WINDOW_PADDING,
329330
2*sizeof(Byte));
330331
/* Avoid use of unitialized values in the window, see crbug.com/1137613 and
331332
* crbug.com/1144420 */
332333
if (s->window) { /* [jart] fix regression in malloc failure checking */
333-
zmemzero(s->window, (s->w_size + window_padding) * (2 * sizeof(Byte)));
334+
zmemzero(s->window, (s->w_size + WINDOW_PADDING) * (2 * sizeof(Byte)));
334335
}
335336
s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
336337
/* Avoid use of uninitialized value, see:
@@ -770,6 +771,12 @@ uLong ZEXPORT deflateBound(strm, sourceLen)
770771
wraplen = 6;
771772
}
772773

774+
/* With Chromium's hashing, s->hash_bits may not correspond to the
775+
memLevel, making the computations below incorrect. Return the
776+
conservative bound. */
777+
if (s->chromium_zlib_hash)
778+
return (fixedlen > storelen ? fixedlen : storelen) + wraplen;
779+
773780
/* if not default parameters, return one of the conservative bounds */
774781
if (s->w_bits != 15 || s->hash_bits != 8 + 7)
775782
return (s->w_bits <= s->hash_bits ? fixedlen : storelen) + wraplen;
@@ -1199,7 +1206,9 @@ int ZEXPORT deflateCopy(dest, source)
11991206
zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state));
12001207
ds->strm = dest;
12011208

1202-
ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
1209+
ds->window = (Bytef *) ZALLOC(dest,
1210+
ds->w_size + WINDOW_PADDING,
1211+
2*sizeof(Byte));
12031212
ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
12041213
ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
12051214
ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, 4);
@@ -1210,7 +1219,8 @@ int ZEXPORT deflateCopy(dest, source)
12101219
return Z_MEM_ERROR;
12111220
}
12121221
/* following zmemcpy do not work for 16-bit MSDOS */
1213-
zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
1222+
zmemcpy(ds->window, ss->window,
1223+
(ds->w_size + WINDOW_PADDING) * 2 * sizeof(Byte));
12141224
zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos));
12151225
zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos));
12161226
zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);

third_party/zlib/inflate.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ int value;
256256
struct inflate_state FAR *state;
257257

258258
if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
259+
if (bits == 0)
260+
return Z_OK;
259261
state = (struct inflate_state FAR *)strm->state;
260262
if (bits < 0) {
261263
state->hold = 0;
@@ -1480,7 +1482,7 @@ z_streamp strm;
14801482
/* if first time, start search in bit buffer */
14811483
if (state->mode != SYNC) {
14821484
state->mode = SYNC;
1483-
state->hold <<= state->bits & 7;
1485+
state->hold >>= state->bits & 7;
14841486
state->bits -= state->bits & 7;
14851487
len = 0;
14861488
while (state->bits >= 8) {
@@ -1551,8 +1553,9 @@ z_streamp source;
15511553
if (copy == Z_NULL) return Z_MEM_ERROR;
15521554
window = Z_NULL;
15531555
if (state->window != Z_NULL) {
1554-
window = (unsigned char FAR *)
1555-
ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
1556+
window = (unsigned char FAR *)ZALLOC(
1557+
source, (1U << state->wbits) + CHUNKCOPY_CHUNK_SIZE,
1558+
sizeof(unsigned char));
15561559
if (window == Z_NULL) {
15571560
ZFREE(source, copy);
15581561
return Z_MEM_ERROR;

0 commit comments

Comments
 (0)