From 42307a8f43e28c8a286aad36f21d647342ad9933 Mon Sep 17 00:00:00 2001 From: Tim Kientzle Date: Wed, 11 May 2005 03:47:48 +0000 Subject: [PATCH] Since the FreeBSD local modifications are mostly trivial (consisting primarily of pointless $FreeBSD$ tags), sync most files in HEAD with those in the ZLIB branch. This minimizes the differences between HEAD and ZLIB and should simplify future imports. After this, there are only three files with local modifications (gzio.c, minigzip.c, and zconf.h) and two non-vendor files (Makefile, zopen.c). The rest exactly match the vendor distribution. PR: i386/76294 MFC after: 2 weeks --- lib/libz/adler32.c | 3 +- lib/libz/compress.c | 3 +- lib/libz/crc32.c | 77 ++++++++++++++++++++++++++++----------------- lib/libz/deflate.c | 9 ++---- lib/libz/deflate.h | 3 +- lib/libz/example.c | 3 +- lib/libz/infback.c | 4 +-- lib/libz/inffast.c | 7 ++--- lib/libz/inflate.c | 8 ++--- lib/libz/inftrees.c | 20 +++++++----- lib/libz/trees.c | 7 ++--- lib/libz/uncompr.c | 3 +- lib/libz/zlib.3 | 8 ++--- lib/libz/zutil.c | 3 +- lib/libz/zutil.h | 9 ++++-- 15 files changed, 90 insertions(+), 77 deletions(-) diff --git a/lib/libz/adler32.c b/lib/libz/adler32.c index 1bf48cf1d87..624a1696eb0 100644 --- a/lib/libz/adler32.c +++ b/lib/libz/adler32.c @@ -3,8 +3,7 @@ * For conditions of distribution and use, see copyright notice in zlib.h */ -#include -__FBSDID("$FreeBSD$"); +/* @(#) $Id$ */ #define ZLIB_INTERNAL #include "zlib.h" diff --git a/lib/libz/compress.c b/lib/libz/compress.c index 7b349f5fb90..24ef0291911 100644 --- a/lib/libz/compress.c +++ b/lib/libz/compress.c @@ -3,8 +3,7 @@ * For conditions of distribution and use, see copyright notice in zlib.h */ -#include -__FBSDID("$FreeBSD$"); +/* @(#) $Id$ */ #define ZLIB_INTERNAL #include "zlib.h" diff --git a/lib/libz/crc32.c b/lib/libz/crc32.c index efb152acea6..b39c7e1253e 100644 --- a/lib/libz/crc32.c +++ b/lib/libz/crc32.c @@ -9,8 +9,15 @@ * of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3. */ -#include -__FBSDID("$FreeBSD$"); +/* @(#) $Id$ */ + +/* + Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore + protection on the static variables used to control the first-use generation + of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should + first call get_crc_table() to initialize the tables before allowing more than + one thread to use crc32(). + */ #ifdef MAKECRCH # include @@ -59,7 +66,7 @@ __FBSDID("$FreeBSD$"); #ifdef DYNAMIC_CRC_TABLE -local int crc_table_empty = 1; +local volatile int crc_table_empty = 1; local unsigned long FAR crc_table[TBLS][256]; local void make_crc_table OF((void)); #ifdef MAKECRCH @@ -96,38 +103,51 @@ local void make_crc_table() { unsigned long c; int n, k; - unsigned long poly; /* polynomial exclusive-or pattern */ + unsigned long poly; /* polynomial exclusive-or pattern */ /* terms of polynomial defining this crc (except x^32): */ + static volatile int first = 1; /* flag to limit concurrent making */ static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26}; - /* make exclusive-or pattern from polynomial (0xedb88320UL) */ - poly = 0UL; - for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++) - poly |= 1UL << (31 - p[n]); + /* See if another task is already doing this (not thread-safe, but better + than nothing -- significantly reduces duration of vulnerability in + case the advice about DYNAMIC_CRC_TABLE is ignored) */ + if (first) { + first = 0; - /* generate a crc for every 8-bit value */ - for (n = 0; n < 256; n++) { - c = (unsigned long)n; - for (k = 0; k < 8; k++) - c = c & 1 ? poly ^ (c >> 1) : c >> 1; - crc_table[0][n] = c; - } + /* make exclusive-or pattern from polynomial (0xedb88320UL) */ + poly = 0UL; + for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++) + poly |= 1UL << (31 - p[n]); + + /* generate a crc for every 8-bit value */ + for (n = 0; n < 256; n++) { + c = (unsigned long)n; + for (k = 0; k < 8; k++) + c = c & 1 ? poly ^ (c >> 1) : c >> 1; + crc_table[0][n] = c; + } #ifdef BYFOUR - /* generate crc for each value followed by one, two, and three zeros, and - then the byte reversal of those as well as the first table */ - for (n = 0; n < 256; n++) { - c = crc_table[0][n]; - crc_table[4][n] = REV(c); - for (k = 1; k < 4; k++) { - c = crc_table[0][c & 0xff] ^ (c >> 8); - crc_table[k][n] = c; - crc_table[k + 4][n] = REV(c); + /* generate crc for each value followed by one, two, and three zeros, + and then the byte reversal of those as well as the first table */ + for (n = 0; n < 256; n++) { + c = crc_table[0][n]; + crc_table[4][n] = REV(c); + for (k = 1; k < 4; k++) { + c = crc_table[0][c & 0xff] ^ (c >> 8); + crc_table[k][n] = c; + crc_table[k + 4][n] = REV(c); + } } - } #endif /* BYFOUR */ - crc_table_empty = 0; + crc_table_empty = 0; + } + else { /* not first */ + /* wait for the other guy to finish (not efficient, but rare) */ + while (crc_table_empty) + ; + } #ifdef MAKECRCH /* write out CRC tables to crc32.h */ @@ -181,9 +201,10 @@ local void write_table(out, table) const unsigned long FAR * ZEXPORT get_crc_table() { #ifdef DYNAMIC_CRC_TABLE - if (crc_table_empty) make_crc_table(); + if (crc_table_empty) + make_crc_table(); #endif /* DYNAMIC_CRC_TABLE */ - return (const unsigned long FAR *)crc_table; + return (const unsigned long FAR *)crc_table; } /* ========================================================================= */ diff --git a/lib/libz/deflate.c b/lib/libz/deflate.c index 155b72a73c5..0fc53bc1e82 100644 --- a/lib/libz/deflate.c +++ b/lib/libz/deflate.c @@ -1,11 +1,8 @@ /* deflate.c -- compress data using the deflation algorithm - * Copyright (C) 1995-2003 Jean-loup Gailly. + * Copyright (C) 1995-2004 Jean-loup Gailly. * For conditions of distribution and use, see copyright notice in zlib.h */ -#include -__FBSDID("$FreeBSD$"); - /* * ALGORITHM * @@ -50,12 +47,12 @@ __FBSDID("$FreeBSD$"); * */ -/* @(#) $FreeBSD$ */ +/* @(#) $Id$ */ #include "deflate.h" const char deflate_copyright[] = - " deflate 1.2.1 Copyright 1995-2003 Jean-loup Gailly "; + " deflate 1.2.2 Copyright 1995-2004 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 diff --git a/lib/libz/deflate.h b/lib/libz/deflate.h index 8f4ff2dda90..410681d18a4 100644 --- a/lib/libz/deflate.h +++ b/lib/libz/deflate.h @@ -8,7 +8,7 @@ subject to change. Applications should only use zlib.h. */ -/* @(#) $FreeBSD$ */ +/* @(#) $Id$ */ #ifndef DEFLATE_H #define DEFLATE_H @@ -95,7 +95,6 @@ typedef struct internal_state { Bytef *pending_out; /* next pending byte to output to the stream */ int pending; /* nb of bytes in the pending buffer */ int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ - Byte data_type; /* UNKNOWN, BINARY or ASCII */ Byte method; /* STORED (for zip only) or DEFLATED */ int last_flush; /* value of flush param for previous deflate call */ diff --git a/lib/libz/example.c b/lib/libz/example.c index c528b62549c..c2361f98f2d 100644 --- a/lib/libz/example.c +++ b/lib/libz/example.c @@ -3,8 +3,7 @@ * For conditions of distribution and use, see copyright notice in zlib.h */ -#include -__FBSDID("$FreeBSD$"); +/* @(#) $Id$ */ #include #include "zlib.h" diff --git a/lib/libz/infback.c b/lib/libz/infback.c index e9709984a89..262f97c73ac 100644 --- a/lib/libz/infback.c +++ b/lib/libz/infback.c @@ -434,8 +434,8 @@ void FAR *out_desc; } } - if (state->mode == BAD) - break; + /* handle error breaks in while */ + if (state->mode == BAD) break; /* build code tables */ state->next = state->codes; diff --git a/lib/libz/inffast.c b/lib/libz/inffast.c index c5c93a5bc22..8c02a178d04 100644 --- a/lib/libz/inffast.c +++ b/lib/libz/inffast.c @@ -1,11 +1,8 @@ /* inffast.c -- fast decoding - * Copyright (C) 1995-2003 Mark Adler + * Copyright (C) 1995-2004 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ -#include -__FBSDID("$FreeBSD$"); - #include "zutil.h" #include "inftrees.h" #include "inflate.h" @@ -22,7 +19,7 @@ __FBSDID("$FreeBSD$"); - none No measurable difference: - Pentium III (Anderson) - - 68060 (Nikl) + - M68060 (Nikl) */ #ifdef POSTINC # define OFF 0 diff --git a/lib/libz/inflate.c b/lib/libz/inflate.c index 913f00296b5..c6d38266d07 100644 --- a/lib/libz/inflate.c +++ b/lib/libz/inflate.c @@ -80,9 +80,6 @@ * The history for versions after 1.2.0 are in ChangeLog in zlib distribution. */ -#include -__FBSDID("$FreeBSD$"); - #include "zutil.h" #include "inftrees.h" #include "inflate.h" @@ -112,6 +109,7 @@ z_streamp strm; state = (struct inflate_state FAR *)strm->state; strm->total_in = strm->total_out = state->total = 0; strm->msg = Z_NULL; + strm->adler = 1; /* to support ill-conceived Java test suite */ state->mode = HEAD; state->last = 0; state->havedict = 0; @@ -864,8 +862,8 @@ int flush; } } - if (state->mode == BAD) - break; + /* handle error breaks in while */ + if (state->mode == BAD) break; /* build code tables */ state->next = state->codes; diff --git a/lib/libz/inftrees.c b/lib/libz/inftrees.c index 4d0b487b450..8a896b28793 100644 --- a/lib/libz/inftrees.c +++ b/lib/libz/inftrees.c @@ -1,18 +1,15 @@ /* inftrees.c -- generate Huffman trees for efficient decoding - * Copyright (C) 1995-2003 Mark Adler + * Copyright (C) 1995-2004 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ -#include -__FBSDID("$FreeBSD$"); - #include "zutil.h" #include "inftrees.h" #define MAXBITS 15 const char inflate_copyright[] = - " inflate 1.2.1 Copyright 1995-2003 Mark Adler "; + " inflate 1.2.2 Copyright 1995-2004 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 @@ -65,7 +62,7 @@ unsigned short FAR *work; 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; static const unsigned short lext[31] = { /* Length codes 257..285 extra */ 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, - 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 76, 66}; + 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 199, 198}; static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, @@ -117,7 +114,15 @@ unsigned short FAR *work; for (max = MAXBITS; max >= 1; max--) if (count[max] != 0) break; if (root > max) root = max; - if (max == 0) return -1; /* no codes! */ + if (max == 0) { /* no symbols to code at all */ + this.op = (unsigned char)64; /* invalid code marker */ + this.bits = (unsigned char)1; + this.val = (unsigned short)0; + *(*table)++ = this; /* make a table to force an error */ + *(*table)++ = this; + *bits = 1; + return 0; /* no symbols, but wait for decoding to report error */ + } for (min = 1; min <= MAXBITS; min++) if (count[min] != 0) break; if (root < min) root = min; @@ -298,7 +303,6 @@ unsigned short FAR *work; drop = 0; len = root; next = *table; - curr = root; this.bits = (unsigned char)len; } diff --git a/lib/libz/trees.c b/lib/libz/trees.c index 3f8289f1083..52c820fa2e9 100644 --- a/lib/libz/trees.c +++ b/lib/libz/trees.c @@ -29,8 +29,7 @@ * Addison-Wesley, 1983. ISBN 0-201-06672-6. */ -#include -__FBSDID("$FreeBSD$"); +/* @(#) $Id$ */ /* #define GEN_TREES_H */ @@ -932,7 +931,7 @@ void _tr_flush_block(s, buf, stored_len, eof) if (s->level > 0) { /* Check if the file is ascii or binary */ - if (s->data_type == Z_UNKNOWN) set_data_type(s); + if (s->strm->data_type == Z_UNKNOWN) set_data_type(s); /* Construct the literal and distance trees */ build_tree(s, (tree_desc *)(&(s->l_desc))); @@ -1132,7 +1131,7 @@ local void set_data_type(s) while (n < 7) bin_freq += s->dyn_ltree[n++].Freq; while (n < 128) ascii_freq += s->dyn_ltree[n++].Freq; while (n < LITERALS) bin_freq += s->dyn_ltree[n++].Freq; - s->data_type = (Byte)(bin_freq > (ascii_freq >> 2) ? Z_BINARY : Z_ASCII); + s->strm->data_type = bin_freq > (ascii_freq >> 2) ? Z_BINARY : Z_ASCII; } /* =========================================================================== diff --git a/lib/libz/uncompr.c b/lib/libz/uncompr.c index a428b5a5cb5..b59e3d0defb 100644 --- a/lib/libz/uncompr.c +++ b/lib/libz/uncompr.c @@ -3,8 +3,7 @@ * For conditions of distribution and use, see copyright notice in zlib.h */ -#include -__FBSDID("$FreeBSD$"); +/* @(#) $Id$ */ #define ZLIB_INTERNAL #include "zlib.h" diff --git a/lib/libz/zlib.3 b/lib/libz/zlib.3 index a1e01960bea..3139e2467f2 100644 --- a/lib/libz/zlib.3 +++ b/lib/libz/zlib.3 @@ -1,6 +1,4 @@ -.\" $FreeBSD$ -.\" -.TH ZLIB 3 "17 November 2003" +.TH ZLIB 3 "3 October 2004" .SH NAME zlib \- compression/decompression library .SH SYNOPSIS @@ -135,8 +133,8 @@ before asking for help. Send questions and/or comments to zlib@gzip.org, or (for the Windows DLL version) to Gilles Vollant (info@winimage.com). .SH AUTHORS -Version 1.2.1 -Copyright (C) 1995-2003 Jean-loup Gailly (jloup@gzip.org) +Version 1.2.2 +Copyright (C) 1995-2004 Jean-loup Gailly (jloup@gzip.org) and Mark Adler (madler@alumni.caltech.edu). .LP This software is provided "as-is," diff --git a/lib/libz/zutil.c b/lib/libz/zutil.c index 8f749cef1a9..0ef4f99f57e 100644 --- a/lib/libz/zutil.c +++ b/lib/libz/zutil.c @@ -3,8 +3,7 @@ * For conditions of distribution and use, see copyright notice in zlib.h */ -#include -__FBSDID("$FreeBSD$"); +/* @(#) $Id$ */ #include "zutil.h" diff --git a/lib/libz/zutil.h b/lib/libz/zutil.h index 60e5d2bc392..7b42edcaa98 100644 --- a/lib/libz/zutil.h +++ b/lib/libz/zutil.h @@ -8,7 +8,7 @@ subject to change. Applications should only use zlib.h. */ -/* @(#) $FreeBSD$ */ +/* @(#) $Id$ */ #ifndef ZUTIL_H #define ZUTIL_H @@ -189,9 +189,14 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ # define NO_vsnprintf # endif #endif +#ifdef VMS +# define NO_vsnprintf +#endif #ifdef HAVE_STRERROR - extern char *strerror OF((int)); +# ifndef VMS + extern char *strerror OF((int)); +# endif # define zstrerror(errnum) strerror(errnum) #else # define zstrerror(errnum) ""