From 8a2acbffc86012de3523ecf91db2c4ea1b1c4ea2 Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Fri, 9 Sep 2011 23:13:27 -0700 Subject: zlib 1.0-pre --- inflate.c | 94 ++++++++++++--------------------------------------------------- 1 file changed, 18 insertions(+), 76 deletions(-) (limited to 'inflate.c') diff --git a/inflate.c b/inflate.c index 1f576e4..b71f74f 100644 --- a/inflate.c +++ b/inflate.c @@ -1,5 +1,5 @@ /* inflate.c -- zlib interface to inflate modules - * Copyright (C) 1995-1996 Mark Adler + * Copyright (C) 1995 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -15,11 +15,6 @@ struct internal_state { enum { METHOD, /* waiting for method byte */ FLAG, /* waiting for flag byte */ - DICT4, /* four dictionary check bytes to go */ - DICT3, /* three dictionary check bytes to go */ - DICT2, /* two dictionary check bytes to go */ - DICT1, /* one dictionary check byte to go */ - DICT0, /* waiting for inflateSetDictionary */ BLOCKS, /* decompressing blocks */ CHECK4, /* four check bytes to go */ CHECK3, /* three check bytes to go */ @@ -80,16 +75,10 @@ z_stream *z; } -int inflateInit2_(z, w, version, stream_size) +int inflateInit2(z, w) z_stream *z; int w; -const char *version; -int stream_size; { - if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || - stream_size != sizeof(z_stream)) - return Z_VERSION_ERROR; - /* initialize state */ if (z == Z_NULL) return Z_STREAM_ERROR; @@ -123,7 +112,7 @@ int stream_size; /* create inflate_blocks state */ if ((z->state->blocks = - inflate_blocks_new(z, z->state->nowrap ? Z_NULL : adler32, (uInt)1 << w)) + inflate_blocks_new(z, z->state->nowrap ? Z_NULL : adler32, 1 << w)) == Z_NULL) { inflateEnd(z); @@ -137,12 +126,10 @@ int stream_size; } -int inflateInit_(z, version, stream_size) +int inflateInit(z) z_stream *z; -const char *version; -int stream_size; { - return inflateInit2_(z, DEF_WBITS, version, stream_size); + return inflateInit2(z, DEF_WBITS); } @@ -156,7 +143,7 @@ int f; int r = f; /* to avoid warning about unused f */ uInt b; - if (z == Z_NULL || z->state == Z_NULL || z->next_in == Z_NULL) + if (z == Z_NULL || z->next_in == Z_NULL) return Z_STREAM_ERROR; r = Z_BUF_ERROR; while (1) switch (z->state->mode) @@ -166,58 +153,36 @@ int f; if (((z->state->sub.method = NEXTBYTE) & 0xf) != Z_DEFLATED) { z->state->mode = BAD; - z->msg = (char*)"unknown compression method"; + z->msg = "unknown compression method"; z->state->sub.marker = 5; /* can't try inflateSync */ break; } if ((z->state->sub.method >> 4) + 8 > z->state->wbits) { z->state->mode = BAD; - z->msg = (char*)"invalid window size"; + z->msg = "invalid window size"; z->state->sub.marker = 5; /* can't try inflateSync */ break; } z->state->mode = FLAG; case FLAG: NEEDBYTE - b = NEXTBYTE; - if (((z->state->sub.method << 8) + b) % 31) + if ((b = NEXTBYTE) & 0x20) { z->state->mode = BAD; - z->msg = (char*)"incorrect header check"; + z->msg = "invalid reserved bit"; z->state->sub.marker = 5; /* can't try inflateSync */ break; } - Trace((stderr, "inflate: zlib header ok\n")); - if (!(b & PRESET_DICT)) + if (((z->state->sub.method << 8) + b) % 31) { - z->state->mode = BLOCKS; - break; + z->state->mode = BAD; + z->msg = "incorrect header check"; + z->state->sub.marker = 5; /* can't try inflateSync */ + break; } - z->state->mode = DICT4; - case DICT4: - NEEDBYTE - z->state->sub.check.need = (uLong)NEXTBYTE << 24; - z->state->mode = DICT3; - case DICT3: - NEEDBYTE - z->state->sub.check.need += (uLong)NEXTBYTE << 16; - z->state->mode = DICT2; - case DICT2: - NEEDBYTE - z->state->sub.check.need += (uLong)NEXTBYTE << 8; - z->state->mode = DICT1; - case DICT1: - NEEDBYTE - z->state->sub.check.need += (uLong)NEXTBYTE; - z->adler = z->state->sub.check.need; - z->state->mode = DICT0; - return Z_NEED_DICT; - case DICT0: - z->state->mode = BAD; - z->msg = (char*)"need dictionary"; - z->state->sub.marker = 0; /* can try inflateSync */ - return Z_STREAM_ERROR; + Trace((stderr, "inflate: zlib header ok\n")); + z->state->mode = BLOCKS; case BLOCKS: r = inflate_blocks(z->state->blocks, z, r); if (r == Z_DATA_ERROR) @@ -255,7 +220,7 @@ int f; if (z->state->sub.check.was != z->state->sub.check.need) { z->state->mode = BAD; - z->msg = (char*)"incorrect data check"; + z->msg = "incorrect data check"; z->state->sub.marker = 5; /* can't try inflateSync */ break; } @@ -271,29 +236,6 @@ int f; } -int inflateSetDictionary(z, dictionary, dictLength) -z_stream *z; -const Bytef *dictionary; -uInt dictLength; -{ - uInt length = dictLength; - - if (z == Z_NULL || z->state == Z_NULL || z->state->mode != DICT0) - return Z_STREAM_ERROR; - if (adler32(1L, dictionary, dictLength) != z->adler) return Z_DATA_ERROR; - z->adler = 1L; - - if (length >= (1<state->wbits)) - { - length = (1<state->wbits)-1; - dictionary += dictLength - length; - } - inflate_set_dictionary(z->state->blocks, z, dictionary, length); - z->state->mode = BLOCKS; - return Z_OK; -} - - int inflateSync(z) z_stream *z; { -- cgit v1.2.3-55-g6feb