diff options
author | Ladislav Zezula <ladislav.zezula@avg.com> | 2013-10-10 08:42:13 +0200 |
---|---|---|
committer | Ladislav Zezula <ladislav.zezula@avg.com> | 2013-10-10 08:42:13 +0200 |
commit | 88b74cc6aff6df067837ded12c30fe59800a8a95 (patch) | |
tree | f5fa89cea35fccccf90304e63fe478f8b317bd01 /src/zlib/inffast.c | |
parent | 24f9faffc938e812ba545d204b9e56052c22ae63 (diff) |
+ Fixed crash when TMPQFile failed to allocate
+ ZLIB updated
Diffstat (limited to 'src/zlib/inffast.c')
-rw-r--r-- | src/zlib/inffast.c | 80 |
1 files changed, 29 insertions, 51 deletions
diff --git a/src/zlib/inffast.c b/src/zlib/inffast.c index 2f1d60b..bbee92e 100644 --- a/src/zlib/inffast.c +++ b/src/zlib/inffast.c @@ -1,5 +1,5 @@ /* inffast.c -- fast decoding - * Copyright (C) 1995-2008, 2010 Mark Adler + * Copyright (C) 1995-2004 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -64,7 +64,7 @@ requires strm->avail_out >= 258 for each loop to avoid checking for output space. */ -void ZLIB_INTERNAL inflate_fast(strm, start) +void inflate_fast(strm, start) z_streamp strm; unsigned start; /* inflate()'s starting value for strm->avail_out */ { @@ -79,7 +79,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ #endif unsigned wsize; /* window size or zero if not using window */ unsigned whave; /* valid bytes in the window */ - unsigned wnext; /* window write index */ + unsigned write; /* window write index */ unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */ unsigned long hold; /* local strm->hold */ unsigned bits; /* local strm->bits */ @@ -87,7 +87,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ code const FAR *dcode; /* local strm->distcode */ unsigned lmask; /* mask for first level of length codes */ unsigned dmask; /* mask for first level of distance codes */ - code here; /* retrieved table entry */ + code this; /* retrieved table entry */ unsigned op; /* code bits, operation, extra bits, or */ /* window position, window bytes to copy */ unsigned len; /* match length, unused bytes */ @@ -106,7 +106,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ #endif wsize = state->wsize; whave = state->whave; - wnext = state->wnext; + write = state->write; window = state->window; hold = state->hold; bits = state->bits; @@ -124,20 +124,20 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ hold += (unsigned long)(PUP(in)) << bits; bits += 8; } - here = lcode[hold & lmask]; + this = lcode[hold & lmask]; dolen: - op = (unsigned)(here.bits); + op = (unsigned)(this.bits); hold >>= op; bits -= op; - op = (unsigned)(here.op); + op = (unsigned)(this.op); if (op == 0) { /* literal */ - Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? + Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ? "inflate: literal '%c'\n" : - "inflate: literal 0x%02x\n", here.val)); - PUP(out) = (unsigned char)(here.val); + "inflate: literal 0x%02x\n", this.val)); + PUP(out) = (unsigned char)(this.val); } else if (op & 16) { /* length base */ - len = (unsigned)(here.val); + len = (unsigned)(this.val); op &= 15; /* number of extra bits */ if (op) { if (bits < op) { @@ -155,14 +155,14 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ hold += (unsigned long)(PUP(in)) << bits; bits += 8; } - here = dcode[hold & dmask]; + this = dcode[hold & dmask]; dodist: - op = (unsigned)(here.bits); + op = (unsigned)(this.bits); hold >>= op; bits -= op; - op = (unsigned)(here.op); + op = (unsigned)(this.op); if (op & 16) { /* distance base */ - dist = (unsigned)(here.val); + dist = (unsigned)(this.val); op &= 15; /* number of extra bits */ if (bits < op) { hold += (unsigned long)(PUP(in)) << bits; @@ -187,34 +187,12 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ if (dist > op) { /* see if copy from window */ op = dist - op; /* distance back in window */ if (op > whave) { - if (state->sane) { - strm->msg = - (char *)"invalid distance too far back"; - state->mode = BAD; - break; - } -#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR - if (len <= op - whave) { - do { - PUP(out) = 0; - } while (--len); - continue; - } - len -= op - whave; - do { - PUP(out) = 0; - } while (--op > whave); - if (op == 0) { - from = out - dist; - do { - PUP(out) = PUP(from); - } while (--len); - continue; - } -#endif + strm->msg = (char *)"invalid distance too far back"; + state->mode = BAD; + break; } from = window - OFF; - if (wnext == 0) { /* very common case */ + if (write == 0) { /* very common case */ from += wsize - op; if (op < len) { /* some from window */ len -= op; @@ -224,17 +202,17 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ from = out - dist; /* rest from output */ } } - else if (wnext < op) { /* wrap around window */ - from += wsize + wnext - op; - op -= wnext; + else if (write < op) { /* wrap around window */ + from += wsize + write - op; + op -= write; if (op < len) { /* some from end of window */ len -= op; do { PUP(out) = PUP(from); } while (--op); from = window - OFF; - if (wnext < len) { /* some from start of window */ - op = wnext; + if (write < len) { /* some from start of window */ + op = write; len -= op; do { PUP(out) = PUP(from); @@ -244,7 +222,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ } } else { /* contiguous in window */ - from += wnext - op; + from += write - op; if (op < len) { /* some from window */ len -= op; do { @@ -281,7 +259,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ } } else if ((op & 64) == 0) { /* 2nd level distance code */ - here = dcode[here.val + (hold & ((1U << op) - 1))]; + this = dcode[this.val + (hold & ((1U << op) - 1))]; goto dodist; } else { @@ -291,7 +269,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ } } else if ((op & 64) == 0) { /* 2nd level length code */ - here = lcode[here.val + (hold & ((1U << op) - 1))]; + this = lcode[this.val + (hold & ((1U << op) - 1))]; goto dolen; } else if (op & 32) { /* end-of-block */ @@ -327,7 +305,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe): - Using bit fields for code structure - Different op definition to avoid & for extra bits (do & for table bits) - - Three separate decoding do-loops for direct, window, and wnext == 0 + - Three separate decoding do-loops for direct, window, and write == 0 - Special case for distance > 1 copies to do overlapped load and store copy - Explicit branch predictions (based on measured branch probabilities) - Deferring match copy and interspersed it with decoding subsequent codes |