diff --git a/deps/libz/inflate.c b/deps/libz/inflate.c index 16c741df26..5403a7bfc0 100644 --- a/deps/libz/inflate.c +++ b/deps/libz/inflate.c @@ -276,7 +276,7 @@ int inflatePrime(z_streamp strm, int bits, int value) return Z_STREAM_ERROR; value &= (1L << bits) - 1; - state->hold += value << state->bits; + state->hold += (unsigned)value << state->bits; state->bits += bits; return Z_OK; @@ -603,6 +603,8 @@ int inflate(z_streamp strm, int flush) NEEDBITS(16); #ifdef GUNZIP if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */ + if (state->wbits == 0) + state->wbits = 15; state->check = crc32(0L, Z_NULL, 0); CRC2(state->check, hold); INITBITS(); @@ -629,8 +631,8 @@ int inflate(z_streamp strm, int flush) DROPBITS(4); len = BITS(4) + 8; if (state->wbits == 0) - state->wbits = len; - else if (len > state->wbits) { + state->wbits = len; + if (len > 15 || len > state->wbits) { strm->msg = (char *)"invalid window size"; state->mode = BAD; break; @@ -1484,10 +1486,10 @@ long inflateMark(z_streamp strm) if ( strm == Z_NULL || strm->state == Z_NULL) - return -1L << 16; + return -(1L << 16); state = (struct inflate_state FAR *)strm->state; - return ((long)(state->back) << 16) + + return (long)(((unsigned long)((long)state->back)) << 16) + (state->mode == COPY ? state->length : (state->mode == MATCH ? state->was - state->length : 0)); } diff --git a/deps/libz/trees.c b/deps/libz/trees.c index 6cae8f3dde..0d609ae15f 100644 --- a/deps/libz/trees.c +++ b/deps/libz/trees.c @@ -103,8 +103,6 @@ static int detect_data_type (deflate_state *s); static unsigned bi_reverse (unsigned value, int length); static void bi_windup (deflate_state *s); static void bi_flush (deflate_state *s); -static void copy_block (deflate_state *s, charf *buf, unsigned len, - int header); # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len) /* Send a code of the given tree. c and tree must not have side effects */ @@ -595,7 +593,11 @@ static void send_all_trees(deflate_state *s, int lcodes, int dcodes, int blcodes void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf, ulg stored_len, int last) { send_bits(s, (STORED_BLOCK<<1)+last, 3); /* send block type */ - copy_block(s, buf, (unsigned)stored_len, 1); /* with header */ + bi_windup(s); /* align on byte boundary */ + put_short(s, (ush)stored_len); + put_short(s, (ush)~stored_len); + memcpy(s->pending_buf + s->pending, buf, stored_len); + s->pending += stored_len; } /* =========================================================================== @@ -874,20 +876,3 @@ void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf, ulg stored_len, s->bi_buf = 0; s->bi_valid = 0; } - - /* =========================================================================== - * Copy a stored block, storing first the length and its - * one's complement if requested. - */ - static void copy_block(deflate_state *s, charf *buf, unsigned len, int header) - { - bi_windup(s); /* align on byte boundary */ - - if (header) { - put_short(s, (ush)len); - put_short(s, (ush)~len); - } - while (len--) { - put_byte(s, *buf++); - } - }