mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-07 06:53:33 +00:00
Import some Chromium Zlib changes
This commit is contained in:
parent
d8fac40f55
commit
a8bc7ac119
3 changed files with 22 additions and 9 deletions
2
third_party/zlib/crc_folding.c
vendored
2
third_party/zlib/crc_folding.c
vendored
|
@ -406,7 +406,7 @@ partial:
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
_mm_storeu_si128((__m128i *)dst, xmm_crc_part);
|
memcpy(dst, src, len); /* TODO: Possibly generate more efficient code. */
|
||||||
partial_fold(s, len, &xmm_crc0, &xmm_crc1, &xmm_crc2, &xmm_crc3,
|
partial_fold(s, len, &xmm_crc0, &xmm_crc1, &xmm_crc2, &xmm_crc3,
|
||||||
&xmm_crc_part);
|
&xmm_crc_part);
|
||||||
done:
|
done:
|
||||||
|
|
20
third_party/zlib/deflate.c
vendored
20
third_party/zlib/deflate.c
vendored
|
@ -229,6 +229,8 @@ int ZEXPORT deflateInit(strm, level)
|
||||||
/* To do: ignore strm->next_in if we use it as window */
|
/* To do: ignore strm->next_in if we use it as window */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define WINDOW_PADDING 8
|
||||||
|
|
||||||
/* ========================================================================= */
|
/* ========================================================================= */
|
||||||
int ZEXPORT deflateInit2(strm, level, method, windowBits, memLevel, strategy)
|
int ZEXPORT deflateInit2(strm, level, method, windowBits, memLevel, strategy)
|
||||||
z_streamp strm;
|
z_streamp strm;
|
||||||
|
@ -238,7 +240,6 @@ int ZEXPORT deflateInit2(strm, level, method, windowBits, memLevel, strategy)
|
||||||
int memLevel;
|
int memLevel;
|
||||||
int strategy;
|
int strategy;
|
||||||
{
|
{
|
||||||
unsigned window_padding = 8;
|
|
||||||
deflate_state *s;
|
deflate_state *s;
|
||||||
int wrap = 1;
|
int wrap = 1;
|
||||||
|
|
||||||
|
@ -325,12 +326,12 @@ int ZEXPORT deflateInit2(strm, level, method, windowBits, memLevel, strategy)
|
||||||
s->hash_shift = ((s->hash_bits + MIN_MATCH-1) / MIN_MATCH);
|
s->hash_shift = ((s->hash_bits + MIN_MATCH-1) / MIN_MATCH);
|
||||||
|
|
||||||
s->window = (Bytef *) ZALLOC(strm,
|
s->window = (Bytef *) ZALLOC(strm,
|
||||||
s->w_size + window_padding,
|
s->w_size + WINDOW_PADDING,
|
||||||
2*sizeof(Byte));
|
2*sizeof(Byte));
|
||||||
/* Avoid use of unitialized values in the window, see crbug.com/1137613 and
|
/* Avoid use of unitialized values in the window, see crbug.com/1137613 and
|
||||||
* crbug.com/1144420 */
|
* crbug.com/1144420 */
|
||||||
if (s->window) { /* [jart] fix regression in malloc failure checking */
|
if (s->window) { /* [jart] fix regression in malloc failure checking */
|
||||||
zmemzero(s->window, (s->w_size + window_padding) * (2 * sizeof(Byte)));
|
zmemzero(s->window, (s->w_size + WINDOW_PADDING) * (2 * sizeof(Byte)));
|
||||||
}
|
}
|
||||||
s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
|
s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
|
||||||
/* Avoid use of uninitialized value, see:
|
/* Avoid use of uninitialized value, see:
|
||||||
|
@ -770,6 +771,12 @@ uLong ZEXPORT deflateBound(strm, sourceLen)
|
||||||
wraplen = 6;
|
wraplen = 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* With Chromium's hashing, s->hash_bits may not correspond to the
|
||||||
|
memLevel, making the computations below incorrect. Return the
|
||||||
|
conservative bound. */
|
||||||
|
if (s->chromium_zlib_hash)
|
||||||
|
return (fixedlen > storelen ? fixedlen : storelen) + wraplen;
|
||||||
|
|
||||||
/* if not default parameters, return one of the conservative bounds */
|
/* if not default parameters, return one of the conservative bounds */
|
||||||
if (s->w_bits != 15 || s->hash_bits != 8 + 7)
|
if (s->w_bits != 15 || s->hash_bits != 8 + 7)
|
||||||
return (s->w_bits <= s->hash_bits ? fixedlen : storelen) + wraplen;
|
return (s->w_bits <= s->hash_bits ? fixedlen : storelen) + wraplen;
|
||||||
|
@ -1199,7 +1206,9 @@ int ZEXPORT deflateCopy(dest, source)
|
||||||
zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state));
|
zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state));
|
||||||
ds->strm = dest;
|
ds->strm = dest;
|
||||||
|
|
||||||
ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
|
ds->window = (Bytef *) ZALLOC(dest,
|
||||||
|
ds->w_size + WINDOW_PADDING,
|
||||||
|
2*sizeof(Byte));
|
||||||
ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
|
ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
|
||||||
ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
|
ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
|
||||||
ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, 4);
|
ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, 4);
|
||||||
|
@ -1210,7 +1219,8 @@ int ZEXPORT deflateCopy(dest, source)
|
||||||
return Z_MEM_ERROR;
|
return Z_MEM_ERROR;
|
||||||
}
|
}
|
||||||
/* following zmemcpy do not work for 16-bit MSDOS */
|
/* following zmemcpy do not work for 16-bit MSDOS */
|
||||||
zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
|
zmemcpy(ds->window, ss->window,
|
||||||
|
(ds->w_size + WINDOW_PADDING) * 2 * sizeof(Byte));
|
||||||
zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos));
|
zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos));
|
||||||
zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos));
|
zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos));
|
||||||
zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
|
zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
|
||||||
|
|
9
third_party/zlib/inflate.c
vendored
9
third_party/zlib/inflate.c
vendored
|
@ -256,6 +256,8 @@ int value;
|
||||||
struct inflate_state FAR *state;
|
struct inflate_state FAR *state;
|
||||||
|
|
||||||
if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
|
if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
|
||||||
|
if (bits == 0)
|
||||||
|
return Z_OK;
|
||||||
state = (struct inflate_state FAR *)strm->state;
|
state = (struct inflate_state FAR *)strm->state;
|
||||||
if (bits < 0) {
|
if (bits < 0) {
|
||||||
state->hold = 0;
|
state->hold = 0;
|
||||||
|
@ -1480,7 +1482,7 @@ z_streamp strm;
|
||||||
/* if first time, start search in bit buffer */
|
/* if first time, start search in bit buffer */
|
||||||
if (state->mode != SYNC) {
|
if (state->mode != SYNC) {
|
||||||
state->mode = SYNC;
|
state->mode = SYNC;
|
||||||
state->hold <<= state->bits & 7;
|
state->hold >>= state->bits & 7;
|
||||||
state->bits -= state->bits & 7;
|
state->bits -= state->bits & 7;
|
||||||
len = 0;
|
len = 0;
|
||||||
while (state->bits >= 8) {
|
while (state->bits >= 8) {
|
||||||
|
@ -1551,8 +1553,9 @@ z_streamp source;
|
||||||
if (copy == Z_NULL) return Z_MEM_ERROR;
|
if (copy == Z_NULL) return Z_MEM_ERROR;
|
||||||
window = Z_NULL;
|
window = Z_NULL;
|
||||||
if (state->window != Z_NULL) {
|
if (state->window != Z_NULL) {
|
||||||
window = (unsigned char FAR *)
|
window = (unsigned char FAR *)ZALLOC(
|
||||||
ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
|
source, (1U << state->wbits) + CHUNKCOPY_CHUNK_SIZE,
|
||||||
|
sizeof(unsigned char));
|
||||||
if (window == Z_NULL) {
|
if (window == Z_NULL) {
|
||||||
ZFREE(source, copy);
|
ZFREE(source, copy);
|
||||||
return Z_MEM_ERROR;
|
return Z_MEM_ERROR;
|
||||||
|
|
Loading…
Reference in a new issue