From 6c1f79a6549830e8a0b00c39f292c0f8ffe156e6 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Tue, 12 Mar 2002 09:34:29 +0000 Subject: [PATCH] Merged changes from zlib 1.1.4. --- zlib/ChangeLog | 22 +++++++++++++++++----- zlib/adler32.c | 2 +- zlib/compress.c | 2 +- zlib/crc32.c | 2 +- zlib/deflate.c | 6 +++--- zlib/deflate.h | 2 +- zlib/example.c | 2 +- zlib/infblock.c | 11 ++++++++--- zlib/infblock.h | 2 +- zlib/infcodes.c | 12 +++--------- zlib/infcodes.h | 2 +- zlib/inffast.c | 47 ++++++++++++++++++++++++++++++----------------- zlib/inffast.h | 2 +- zlib/inflate.c | 2 +- zlib/inftrees.c | 9 ++++----- zlib/inftrees.h | 2 +- zlib/infutil.c | 2 +- zlib/infutil.h | 2 +- zlib/trees.c | 2 +- zlib/uncompr.c | 2 +- zlib/zconf.h | 2 +- zlib/zlib.h | 6 +++--- zlib/zutil.c | 2 +- zlib/zutil.h | 2 +- 24 files changed, 85 insertions(+), 62 deletions(-) diff --git a/zlib/ChangeLog b/zlib/ChangeLog index 0ae19e2ce..5f06bcc7b 100644 --- a/zlib/ChangeLog +++ b/zlib/ChangeLog @@ -1,3 +1,7 @@ +2002-03-12 Werner Koch + + Merged changes from zlib 1.1.4. + Sat Feb 13 12:04:43 CET 1999 Werner Koch * Makefile.am: Removed -Wall @@ -8,19 +12,27 @@ Wed Jan 20 21:40:21 CET 1999 Werner Koch Wed Jan 13 14:10:15 CET 1999 Werner Koch - - * Merged version 1.1.13 with the previousy used 1.0.4 + Merged version 1.1.3 with the previousy used 1.0.4 Thu Feb 12 12:20:45 1998 Werner Koch (wk@frodo) -- removed a couple of files, as this is only used if zlib is - missing on a system. -- added automake stuff + Removed a couple of files, as this is only used if zlib is + missing on a system. Added automake stuff ChangeLog file for zlib +Changes in 1.1.4 (11 March 2002) +- ZFREE was repeated on same allocation on some error conditions. + This creates a security problem described in + http://www.zlib.org/advisory-2002-03-11.txt +- Returned incorrect error (Z_MEM_ERROR) on some invalid data +- Avoid accesses before window for invalid distances with inflate window + less than 32K. +- force windowBits > 8 to avoid a bug in the encoder for a window size + of 256 bytes. (A complete fix will be available in 1.1.5). + Changes in 1.1.3 (9 July 1998) - fix "an inflate input buffer bug that shows up on rare but persistent occasions" (Mark) diff --git a/zlib/adler32.c b/zlib/adler32.c index 16cf9a703..fae88b655 100644 --- a/zlib/adler32.c +++ b/zlib/adler32.c @@ -1,5 +1,5 @@ /* adler32.c -- compute the Adler-32 checksum of a data stream - * Copyright (C) 1995-1998 Mark Adler + * Copyright (C) 1995-2002 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ diff --git a/zlib/compress.c b/zlib/compress.c index 1cee47091..814bd9d60 100644 --- a/zlib/compress.c +++ b/zlib/compress.c @@ -1,5 +1,5 @@ /* compress.c -- compress a memory buffer - * Copyright (C) 1995-1998 Jean-loup Gailly. + * Copyright (C) 1995-2002 Jean-loup Gailly. * For conditions of distribution and use, see copyright notice in zlib.h */ diff --git a/zlib/crc32.c b/zlib/crc32.c index a91101a81..60deca2dd 100644 --- a/zlib/crc32.c +++ b/zlib/crc32.c @@ -1,5 +1,5 @@ /* crc32.c -- compute the CRC-32 of a data stream - * Copyright (C) 1995-1998 Mark Adler + * Copyright (C) 1995-2002 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ diff --git a/zlib/deflate.c b/zlib/deflate.c index 25d5818e2..16ebdade3 100644 --- a/zlib/deflate.c +++ b/zlib/deflate.c @@ -1,5 +1,5 @@ /* deflate.c -- compress data using the deflation algorithm - * Copyright (C) 1995-1998 Jean-loup Gailly. + * Copyright (C) 1995-2002 Jean-loup Gailly. * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -52,7 +52,7 @@ #include "deflate.h" const char deflate_copyright[] = - " deflate 1.1.3 Copyright 1995-1998 Jean-loup Gailly "; + " deflate 1.1.4 Copyright 1995-2002 Jean-loup Gailly "; /* If you use the zlib library in a product, an acknowledgment is welcome in the documentation of your product. If for some reason you cannot @@ -242,7 +242,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, windowBits = -windowBits; } if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED || - windowBits < 8 || windowBits > 15 || level < 0 || level > 9 || + windowBits < 9 || windowBits > 15 || level < 0 || level > 9 || strategy < 0 || strategy > Z_HUFFMAN_ONLY) { return Z_STREAM_ERROR; } diff --git a/zlib/deflate.h b/zlib/deflate.h index 962676da8..b99a48a52 100644 --- a/zlib/deflate.h +++ b/zlib/deflate.h @@ -1,5 +1,5 @@ /* deflate.h -- internal compression state - * Copyright (C) 1995-1998 Jean-loup Gailly + * Copyright (C) 1995-2002 Jean-loup Gailly * For conditions of distribution and use, see copyright notice in zlib.h */ diff --git a/zlib/example.c b/zlib/example.c index 8307c841e..e7e367333 100644 --- a/zlib/example.c +++ b/zlib/example.c @@ -1,5 +1,5 @@ /* example.c -- usage example of the zlib compression library - * Copyright (C) 1995-1998 Jean-loup Gailly. + * Copyright (C) 1995-2002 Jean-loup Gailly. * For conditions of distribution and use, see copyright notice in zlib.h */ diff --git a/zlib/infblock.c b/zlib/infblock.c index f4920faa5..dd7a6d40a 100644 --- a/zlib/infblock.c +++ b/zlib/infblock.c @@ -1,5 +1,5 @@ /* infblock.c -- interpret and process block types to last block - * Copyright (C) 1995-1998 Mark Adler + * Copyright (C) 1995-2002 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -249,10 +249,12 @@ int r; &s->sub.trees.tb, s->hufts, z); if (t != Z_OK) { - ZFREE(z, s->sub.trees.blens); r = t; if (r == Z_DATA_ERROR) + { + ZFREE(z, s->sub.trees.blens); s->mode = BAD; + } LEAVE } s->sub.trees.index = 0; @@ -313,11 +315,13 @@ int r; t = inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f), s->sub.trees.blens, &bl, &bd, &tl, &td, s->hufts, z); - ZFREE(z, s->sub.trees.blens); if (t != Z_OK) { if (t == (uInt)Z_DATA_ERROR) + { + ZFREE(z, s->sub.trees.blens); s->mode = BAD; + } r = t; LEAVE } @@ -329,6 +333,7 @@ int r; } s->sub.decode.codes = c; } + ZFREE(z, s->sub.trees.blens); s->mode = CODES; case CODES: UPDATE diff --git a/zlib/infblock.h b/zlib/infblock.h index bd25c8075..173b2267a 100644 --- a/zlib/infblock.h +++ b/zlib/infblock.h @@ -1,5 +1,5 @@ /* infblock.h -- header to use infblock.c - * Copyright (C) 1995-1998 Mark Adler + * Copyright (C) 1995-2002 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ diff --git a/zlib/infcodes.c b/zlib/infcodes.c index d4e5ee9a5..9abe5412b 100644 --- a/zlib/infcodes.c +++ b/zlib/infcodes.c @@ -1,5 +1,5 @@ /* infcodes.c -- process literals and length/distance pairs - * Copyright (C) 1995-1998 Mark Adler + * Copyright (C) 1995-2002 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -196,15 +196,9 @@ int r; Tracevv((stderr, "inflate: distance %u\n", c->sub.copy.dist)); c->mode = COPY; case COPY: /* o: copying bytes in window, waiting for space */ -#ifndef __TURBOC__ /* Turbo C bug for following expression */ - f = (uInt)(q - s->window) < c->sub.copy.dist ? - s->end - (c->sub.copy.dist - (q - s->window)) : - q - c->sub.copy.dist; -#else f = q - c->sub.copy.dist; - if ((uInt)(q - s->window) < c->sub.copy.dist) - f = s->end - (c->sub.copy.dist - (uInt)(q - s->window)); -#endif + while (f < s->window) /* modulo window size-"while" instead */ + f += s->end - s->window; /* of "if" handles invalid distances */ while (c->len) { NEEDOUT diff --git a/zlib/infcodes.h b/zlib/infcodes.h index 6c750d896..46821a02b 100644 --- a/zlib/infcodes.h +++ b/zlib/infcodes.h @@ -1,5 +1,5 @@ /* infcodes.h -- header to use infcodes.c - * Copyright (C) 1995-1998 Mark Adler + * Copyright (C) 1995-2002 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ diff --git a/zlib/inffast.c b/zlib/inffast.c index 61a78ee93..aa7f1d4d2 100644 --- a/zlib/inffast.c +++ b/zlib/inffast.c @@ -1,5 +1,5 @@ /* inffast.c -- process literals and length/distance pairs fast - * Copyright (C) 1995-1998 Mark Adler + * Copyright (C) 1995-2002 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -93,28 +93,41 @@ z_streamp z; /* do the copy */ m -= c; - if ((uInt)(q - s->window) >= d) /* offset before dest */ - { /* just copy */ - r = q - d; - *q++ = *r++; c--; /* minimum count is three, */ - *q++ = *r++; c--; /* so unroll loop a little */ - } - else /* else offset after destination */ + r = q - d; + if (r < s->window) /* wrap if needed */ { - e = d - (uInt)(q - s->window); /* bytes from offset to end */ - r = s->end - e; /* pointer to offset */ - if (c > e) /* if source crosses, */ + do { + r += s->end - s->window; /* force pointer in window */ + } while (r < s->window); /* covers invalid distances */ + e = s->end - r; + if (c > e) { - c -= e; /* copy to end of window */ + c -= e; /* wrapped copy */ do { - *q++ = *r++; + *q++ = *r++; } while (--e); - r = s->window; /* copy rest from start of window */ + r = s->window; + do { + *q++ = *r++; + } while (--c); + } + else /* normal copy */ + { + *q++ = *r++; c--; + *q++ = *r++; c--; + do { + *q++ = *r++; + } while (--c); } } - do { /* copy all or what's left */ - *q++ = *r++; - } while (--c); + else /* normal copy */ + { + *q++ = *r++; c--; + *q++ = *r++; c--; + do { + *q++ = *r++; + } while (--c); + } break; } else if ((e & 64) == 0) diff --git a/zlib/inffast.h b/zlib/inffast.h index 8facec553..a31a4bbb0 100644 --- a/zlib/inffast.h +++ b/zlib/inffast.h @@ -1,5 +1,5 @@ /* inffast.h -- header to use inffast.c - * Copyright (C) 1995-1998 Mark Adler + * Copyright (C) 1995-2002 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ diff --git a/zlib/inflate.c b/zlib/inflate.c index 32e9b8de6..dfb2e867d 100644 --- a/zlib/inflate.c +++ b/zlib/inflate.c @@ -1,5 +1,5 @@ /* inflate.c -- zlib interface to inflate modules - * Copyright (C) 1995-1998 Mark Adler + * Copyright (C) 1995-2002 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ diff --git a/zlib/inftrees.c b/zlib/inftrees.c index ef1e0b6b8..4c32ca30d 100644 --- a/zlib/inftrees.c +++ b/zlib/inftrees.c @@ -1,5 +1,5 @@ /* inftrees.c -- generate Huffman trees for efficient decoding - * Copyright (C) 1995-1998 Mark Adler + * Copyright (C) 1995-2002 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -11,7 +11,7 @@ #endif const char inflate_copyright[] = - " inflate 1.1.3 Copyright 1995-1998 Mark Adler "; + " inflate 1.1.4 Copyright 1995-2002 Mark Adler "; /* If you use the zlib library in a product, an acknowledgment is welcome in the documentation of your product. If for some reason you cannot @@ -104,8 +104,7 @@ uIntf *v; /* working area: values in order of bit length */ /* Given a list of code lengths and a maximum table size, make a set of tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR if the given code set is incomplete (the tables are still built in this - case), Z_DATA_ERROR if the input is invalid (an over-subscribed set of - lengths), or Z_MEM_ERROR if not enough memory. */ + case), or Z_DATA_ERROR if the input is invalid. */ { uInt a; /* counter for codes of length k */ @@ -231,7 +230,7 @@ uIntf *v; /* working area: values in order of bit length */ /* allocate new table */ if (*hn + z > MANY) /* (note: doesn't matter for fixed) */ - return Z_MEM_ERROR; /* not enough memory */ + return Z_DATA_ERROR; /* overflow of MANY */ u[h] = q = hp + *hn; *hn += z; diff --git a/zlib/inftrees.h b/zlib/inftrees.h index 85853e097..04b73b729 100644 --- a/zlib/inftrees.h +++ b/zlib/inftrees.h @@ -1,5 +1,5 @@ /* inftrees.h -- header to use inftrees.c - * Copyright (C) 1995-1998 Mark Adler + * Copyright (C) 1995-2002 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ diff --git a/zlib/infutil.c b/zlib/infutil.c index 824dab571..9a076221f 100644 --- a/zlib/infutil.c +++ b/zlib/infutil.c @@ -1,5 +1,5 @@ /* inflate_util.c -- data and routines common to blocks and codes - * Copyright (C) 1995-1998 Mark Adler + * Copyright (C) 1995-2002 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ diff --git a/zlib/infutil.h b/zlib/infutil.h index 99d1135d0..4401df82f 100644 --- a/zlib/infutil.h +++ b/zlib/infutil.h @@ -1,5 +1,5 @@ /* infutil.h -- types and macros common to blocks and codes - * Copyright (C) 1995-1998 Mark Adler + * Copyright (C) 1995-2002 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ diff --git a/zlib/trees.c b/zlib/trees.c index f01fb30d8..0a9840567 100644 --- a/zlib/trees.c +++ b/zlib/trees.c @@ -1,5 +1,5 @@ /* trees.c -- output deflated data using Huffman coding - * Copyright (C) 1995-1998 Jean-loup Gailly + * Copyright (C) 1995-2002 Jean-loup Gailly * For conditions of distribution and use, see copyright notice in zlib.h */ diff --git a/zlib/uncompr.c b/zlib/uncompr.c index d10332137..a287714f5 100644 --- a/zlib/uncompr.c +++ b/zlib/uncompr.c @@ -1,5 +1,5 @@ /* uncompr.c -- decompress a memory buffer - * Copyright (C) 1995-1998 Jean-loup Gailly. + * Copyright (C) 1995-2002 Jean-loup Gailly. * For conditions of distribution and use, see copyright notice in zlib.h */ diff --git a/zlib/zconf.h b/zlib/zconf.h index 6d450fc79..eb0ae2e1a 100644 --- a/zlib/zconf.h +++ b/zlib/zconf.h @@ -1,5 +1,5 @@ /* zconf.h -- configuration of the zlib compression library - * Copyright (C) 1995-1998 Jean-loup Gailly. + * Copyright (C) 1995-2002 Jean-loup Gailly. * For conditions of distribution and use, see copyright notice in zlib.h */ diff --git a/zlib/zlib.h b/zlib/zlib.h index 49f56b43b..52cb529f6 100644 --- a/zlib/zlib.h +++ b/zlib/zlib.h @@ -1,7 +1,7 @@ /* zlib.h -- interface of the 'zlib' general purpose compression library - version 1.1.3, July 9th, 1998 + version 1.1.4, March 11th, 2002 - Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler + Copyright (C) 1995-2002 Jean-loup Gailly and Mark Adler This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages @@ -37,7 +37,7 @@ extern "C" { #endif -#define ZLIB_VERSION "1.1.3" +#define ZLIB_VERSION "1.1.4" /* The 'zlib' compression library provides in-memory compression and diff --git a/zlib/zutil.c b/zlib/zutil.c index b3de4e883..dfc38ec14 100644 --- a/zlib/zutil.c +++ b/zlib/zutil.c @@ -1,5 +1,5 @@ /* zutil.c -- target dependent utility functions for the compression library - * Copyright (C) 1995-1998 Jean-loup Gailly. + * Copyright (C) 1995-2002 Jean-loup Gailly. * For conditions of distribution and use, see copyright notice in zlib.h */ diff --git a/zlib/zutil.h b/zlib/zutil.h index 6f2cb97ca..718ebc15b 100644 --- a/zlib/zutil.h +++ b/zlib/zutil.h @@ -1,5 +1,5 @@ /* zutil.h -- internal interface and configuration of the compression library - * Copyright (C) 1995-1998 Jean-loup Gailly. + * Copyright (C) 1995-2002 Jean-loup Gailly. * For conditions of distribution and use, see copyright notice in zlib.h */