From 913afb9174bb474104049906c1382dec81826424 Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Fri, 9 Sep 2011 22:52:17 -0700 Subject: zlib 0.79 --- inflate.c | 56 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 23 deletions(-) (limited to 'inflate.c') diff --git a/inflate.c b/inflate.c index 478f46d..38d70cc 100644 --- a/inflate.c +++ b/inflate.c @@ -25,10 +25,6 @@ struct internal_state { ERROR} /* got an error--stay here */ mode; /* current inflate mode */ - int no_header; - uInt w_size; /* LZ77 window size (32K by default) */ - uInt w_bits; /* log2(w_size) (8..16) */ - /* mode dependent information */ union { uInt method; /* if FLAGS, method byte */ @@ -39,19 +35,26 @@ struct internal_state { uLong need; /* stream check value */ } check; /* if CHECK, check values to compare */ } sub; /* submode */ + + /* mode independent information */ + int nowrap; /* flag for no wrapper */ + uInt wbits; /* log2(window size) (8..15, defaults to 15) */ + }; -int inflateInit (strm) -z_stream *strm; +int inflateInit(z) +z_stream *z; { - return inflateInit2(strm, WBITS); + return inflateInit2(z, WBITS); } -int inflateInit2(z, windowBits) + +int inflateInit2(z, w) z_stream *z; -int windowBits; +int w; { + /* initialize state */ if (z == Z_NULL) return Z_STREAM_ERROR; if (z->zalloc == Z_NULL) z->zalloc = zcalloc; @@ -63,19 +66,22 @@ int windowBits; return Z_MEM_ERROR; z->state->mode = METHOD; - z->state->no_header = 0; - if (windowBits < 0) { /* undocumented feature: no zlib header */ - windowBits = - windowBits; - z->state->no_header = 1; - z->state->sub.method = DEFLATED; + /* handle undocumented nowrap option (no zlib header or check) */ + z->state->nowrap = 0; + if (w < 0) + { + w = - w; + z->state->nowrap = 1; z->state->mode = START; } - if (windowBits < 8 || windowBits > 15) { + + /* set window size */ + if (w < 8 || w > 15) + { inflateEnd(z); return Z_STREAM_ERROR; } - z->state->w_bits = windowBits; - z->state->w_size = 1<state->wbits = w; return Z_OK; } @@ -103,7 +109,7 @@ int f; z->msg = "unknown compression method"; return Z_DATA_ERROR; } - if ((z->state->sub.method >> 4) > z->state->w_bits) + if ((z->state->sub.method >> 4) + 8 > z->state->wbits) { z->state->mode = ERROR; z->msg = "invalid window size"; @@ -126,17 +132,21 @@ int f; } z->state->mode = START; case START: - if ((z->state->sub.blocks = inflate_blocks_new(z,z->state->w_size)) - == Z_NULL) + if ((z->state->sub.blocks = inflate_blocks_new(z, + z->state->nowrap ? Z_NULL : adler32, + 1<< z->state->wbits)) == Z_NULL) return Z_MEM_ERROR; z->state->mode = BLOCKS; case BLOCKS: if ((r = inflate_blocks(z->state->sub.blocks, z, r)) != Z_STREAM_END) return r; inflate_blocks_free(z->state->sub.blocks, z, &c, &r); - if (z->state->no_header) { - z->state->mode = DONE; - return Z_STREAM_END; + if (z->state->nowrap) + { + if (r != -1) + z->msg = "inflate bug--took one too many bytes"; + z->state->mode = r == -1 ? DONE : ERROR; + break; } z->state->sub.check.was = c; if (r != -1) -- cgit v1.2.3-55-g6feb