Skip to content

Commit f7aee86

Browse files
Import zlib-1.2.3 library
1 parent 535ba76 commit f7aee86

22 files changed

Lines changed: 1008 additions & 213 deletions

zlib/ChangeLog

Lines changed: 92 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,96 @@
11

22
ChangeLog file for zlib
3-
Changes in port for MySQL (19 July 2004)
4-
- removed contrib, nt, os2, amiga, directories and some other files not used
5-
in MySQL distribution. If you are working on porting MySQL to one of rare
6-
platforms, you might find worth looking at the original zlib distribution
7-
and using appropriate Makefiles/project files from it.
3+
4+
Changes in 1.2.3 (18 July 2005)
5+
- Apply security vulnerability fixes to contrib/infback9 as well
6+
- Clean up some text files (carriage returns, trailing space)
7+
- Update testzlib, vstudio, masmx64, and masmx86 in contrib [Vollant]
8+
9+
Changes in 1.2.2.4 (11 July 2005)
10+
- Add inflatePrime() function for starting inflation at bit boundary
11+
- Avoid some Visual C warnings in deflate.c
12+
- Avoid more silly Visual C warnings in inflate.c and inftrees.c for 64-bit
13+
compile
14+
- Fix some spelling errors in comments [Betts]
15+
- Correct inflateInit2() error return documentation in zlib.h
16+
- Added zran.c example of compressed data random access to examples
17+
directory, shows use of inflatePrime()
18+
- Fix cast for assignments to strm->state in inflate.c and infback.c
19+
- Fix zlibCompileFlags() in zutil.c to use 1L for long shifts [Oberhumer]
20+
- Move declarations of gf2 functions to right place in crc32.c [Oberhumer]
21+
- Add cast in trees.c t avoid a warning [Oberhumer]
22+
- Avoid some warnings in fitblk.c, gun.c, gzjoin.c in examples [Oberhumer]
23+
- Update make_vms.com [Zinser]
24+
- Initialize state->write in inflateReset() since copied in inflate_fast()
25+
- Be more strict on incomplete code sets in inflate_table() and increase
26+
ENOUGH and MAXD -- this repairs a possible security vulnerability for
27+
invalid inflate input. Thanks to Tavis Ormandy and Markus Oberhumer for
28+
discovering the vulnerability and providing test cases.
29+
- Add ia64 support to configure for HP-UX [Smith]
30+
- Add error return to gzread() for format or i/o error [Levin]
31+
- Use malloc.h for OS/2 [Necasek]
32+
33+
Changes in 1.2.2.3 (27 May 2005)
34+
- Replace 1U constants in inflate.c and inftrees.c for 64-bit compile
35+
- Typecast fread() return values in gzio.c [Vollant]
36+
- Remove trailing space in minigzip.c outmode (VC++ can't deal with it)
37+
- Fix crc check bug in gzread() after gzungetc() [Heiner]
38+
- Add the deflateTune() function to adjust internal compression parameters
39+
- Add a fast gzip decompressor, gun.c, to examples (use of inflateBack)
40+
- Remove an incorrect assertion in examples/zpipe.c
41+
- Add C++ wrapper in infback9.h [Donais]
42+
- Fix bug in inflateCopy() when decoding fixed codes
43+
- Note in zlib.h how much deflateSetDictionary() actually uses
44+
- Remove USE_DICT_HEAD in deflate.c (would mess up inflate if used)
45+
- Add _WIN32_WCE to define WIN32 in zconf.in.h [Spencer]
46+
- Don't include stderr.h or errno.h for _WIN32_WCE in zutil.h [Spencer]
47+
- Add gzdirect() function to indicate transparent reads
48+
- Update contrib/minizip [Vollant]
49+
- Fix compilation of deflate.c when both ASMV and FASTEST [Oberhumer]
50+
- Add casts in crc32.c to avoid warnings [Oberhumer]
51+
- Add contrib/masmx64 [Vollant]
52+
- Update contrib/asm586, asm686, masmx86, testzlib, vstudio [Vollant]
53+
54+
Changes in 1.2.2.2 (30 December 2004)
55+
- Replace structure assignments in deflate.c and inflate.c with zmemcpy to
56+
avoid implicit memcpy calls (portability for no-library compilation)
57+
- Increase sprintf() buffer size in gzdopen() to allow for large numbers
58+
- Add INFLATE_STRICT to check distances against zlib header
59+
- Improve WinCE errno handling and comments [Chang]
60+
- Remove comment about no gzip header processing in FAQ
61+
- Add Z_FIXED strategy option to deflateInit2() to force fixed trees
62+
- Add updated make_vms.com [Coghlan], update README
63+
- Create a new "examples" directory, move gzappend.c there, add zpipe.c,
64+
fitblk.c, gzlog.[ch], gzjoin.c, and zlib_how.html.
65+
- Add FAQ entry and comments in deflate.c on uninitialized memory access
66+
- Add Solaris 9 make options in configure [Gilbert]
67+
- Allow strerror() usage in gzio.c for STDC
68+
- Fix DecompressBuf in contrib/delphi/ZLib.pas [ManChesTer]
69+
- Update contrib/masmx86/inffas32.asm and gvmat32.asm [Vollant]
70+
- Use z_off_t for adler32_combine() and crc32_combine() lengths
71+
- Make adler32() much faster for small len
72+
- Use OS_CODE in deflate() default gzip header
73+
74+
Changes in 1.2.2.1 (31 October 2004)
75+
- Allow inflateSetDictionary() call for raw inflate
76+
- Fix inflate header crc check bug for file names and comments
77+
- Add deflateSetHeader() and gz_header structure for custom gzip headers
78+
- Add inflateGetheader() to retrieve gzip headers
79+
- Add crc32_combine() and adler32_combine() functions
80+
- Add alloc_func, free_func, in_func, out_func to Z_PREFIX list
81+
- Use zstreamp consistently in zlib.h (inflate_back functions)
82+
- Remove GUNZIP condition from definition of inflate_mode in inflate.h
83+
and in contrib/inflate86/inffast.S [Truta, Anderson]
84+
- Add support for AMD64 in contrib/inflate86/inffas86.c [Anderson]
85+
- Update projects/README.projects and projects/visualc6 [Truta]
86+
- Update win32/DLL_FAQ.txt [Truta]
87+
- Avoid warning under NO_GZCOMPRESS in gzio.c; fix typo [Truta]
88+
- Deprecate Z_ASCII; use Z_TEXT instead [Truta]
89+
- Use a new algorithm for setting strm->data_type in trees.c [Truta]
90+
- Do not define an exit() prototype in zutil.c unless DEBUG defined
91+
- Remove prototype of exit() from zutil.c, example.c, minigzip.c [Truta]
92+
- Add comment in zlib.h for Z_NO_FLUSH parameter to deflate()
93+
- Fix Darwin build version identification [Peterson]
894

995
Changes in 1.2.2 (3 October 2004)
1096
- Update zlib.h comments on gzip in-memory processing
@@ -454,7 +540,7 @@ Changes in 1.0.7 (20 Jan 1998)
454540
Changes in 1.0.6 (19 Jan 1998)
455541
- add functions gzprintf, gzputc, gzgetc, gztell, gzeof, gzseek, gzrewind and
456542
gzsetparams (thanks to Roland Giersig and Kevin Ruland for some of this code)
457-
- Fix a deflate bug occuring only with compression level 0 (thanks to
543+
- Fix a deflate bug occurring only with compression level 0 (thanks to
458544
Andy Buckler for finding this one).
459545
- In minigzip, pass transparently also the first byte for .Z files.
460546
- return Z_BUF_ERROR instead of Z_OK if output buffer full in uncompress()

zlib/FAQ

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,6 @@ The lastest zlib FAQ is at http://www.gzip.org/zlib/zlib_faq.html
148148
format using deflateInit2(). You can also request that inflate decode
149149
the gzip format using inflateInit2(). Read zlib.h for more details.
150150

151-
Note that you cannot specify special gzip header contents (e.g. a file
152-
name or modification date), nor will inflate tell you what was in the
153-
gzip header. If you need to customize the header or see what's in it,
154-
you can use the raw deflate and inflate operations and the crc32()
155-
function and roll your own gzip encoding and decoding. Read the gzip
156-
RFC 1952 for details of the header and trailer format.
157-
158151
21. Is zlib thread-safe?
159152

160153
Yes. However any library routines that zlib uses and any application-
@@ -295,20 +288,29 @@ The lastest zlib FAQ is at http://www.gzip.org/zlib/zlib_faq.html
295288
were downright silly. So now, we simply make sure that the code always
296289
works.
297290

298-
36. Will zlib read the (insert any ancient or arcane format here) compressed
291+
36. Valgrind (or some similar memory access checker) says that deflate is
292+
performing a conditional jump that depends on an uninitialized value.
293+
Isn't that a bug?
294+
295+
No. That is intentional for performance reasons, and the output of
296+
deflate is not affected. This only started showing up recently since
297+
zlib 1.2.x uses malloc() by default for allocations, whereas earlier
298+
versions used calloc(), which zeros out the allocated memory.
299+
300+
37. Will zlib read the (insert any ancient or arcane format here) compressed
299301
data format?
300302

301303
Probably not. Look in the comp.compression FAQ for pointers to various
302304
formats and associated software.
303305

304-
37. How can I encrypt/decrypt zip files with zlib?
306+
38. How can I encrypt/decrypt zip files with zlib?
305307

306308
zlib doesn't support encryption. The original PKZIP encryption is very weak
307309
and can be broken with freely available programs. To get strong encryption,
308310
use GnuPG, http://www.gnupg.org/ , which already includes zlib compression.
309311
For PKZIP compatible "encryption", look at http://www.info-zip.org/
310312

311-
38. What's the difference between the "gzip" and "deflate" HTTP 1.1 encodings?
313+
39. What's the difference between the "gzip" and "deflate" HTTP 1.1 encodings?
312314

313315
"gzip" is the gzip format, and "deflate" is the zlib format. They should
314316
probably have called the second one "zlib" instead to avoid confusion
@@ -324,14 +326,14 @@ The lastest zlib FAQ is at http://www.gzip.org/zlib/zlib_faq.html
324326

325327
Bottom line: use the gzip format for HTTP 1.1 encoding.
326328

327-
39. Does zlib support the new "Deflate64" format introduced by PKWare?
329+
40. Does zlib support the new "Deflate64" format introduced by PKWare?
328330

329331
No. PKWare has apparently decided to keep that format proprietary, since
330332
they have not documented it as they have previous compression formats.
331333
In any case, the compression improvements are so modest compared to other
332334
more modern approaches, that it's not worth the effort to implement.
333335

334-
40. Can you please sign these lengthy legal documents and fax them back to us
336+
41. Can you please sign these lengthy legal documents and fax them back to us
335337
so that we can use your software in our product?
336338

337339
No. Go away. Shoo.

zlib/README

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ZLIB DATA COMPRESSION LIBRARY
22

3-
zlib 1.2.2 is a general purpose data compression library. All the code is
3+
zlib 1.2.3 is a general purpose data compression library. All the code is
44
thread safe. The data format used by the zlib library is described by RFCs
55
(Request for Comments) 1950 to 1952 in the files
66
http://www.ietf.org/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format)
@@ -16,9 +16,8 @@ minigzip.c.
1616

1717
To compile all files and run the test program, follow the instructions given at
1818
the top of Makefile. In short "make test; make install" should work for most
19-
machines. For Unix: "./configure; make test; make install" For MSDOS, use one
20-
of the special makefiles such as Makefile.msc. For VMS, use Make_vms.com or
21-
descrip.mms.
19+
machines. For Unix: "./configure; make test; make install". For MSDOS, use one
20+
of the special makefiles such as Makefile.msc. For VMS, use make_vms.com.
2221

2322
Questions about zlib should be sent to <[email protected]>, or to Gilles Vollant
2423
<[email protected]> for the Windows DLL version. The zlib home page is
@@ -34,7 +33,7 @@ Mark Nelson <[email protected]> wrote an article about zlib for the Jan. 1997
3433
issue of Dr. Dobb's Journal; a copy of the article is available in
3534
http://dogma.net/markn/articles/zlibtool/zlibtool.htm
3635

37-
The changes made in version 1.2.2 are documented in the file ChangeLog.
36+
The changes made in version 1.2.3 are documented in the file ChangeLog.
3837

3938
Unsupported third party contributions are provided in directory "contrib".
4039

zlib/README.MySQL

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
This an incomplete version of the zlib library -- it excludes some of the
2+
platform-specific project files, contributed code, and examples from the
3+
original zlib distribution. You can find the original distribution at
4+
5+
http://www.gzip.org/zlib/
6+
or
7+
http://www.zlib.net/

zlib/adler32.c

Lines changed: 93 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* adler32.c -- compute the Adler-32 checksum of a data stream
2-
* Copyright (C) 1995-2003 Mark Adler
2+
* Copyright (C) 1995-2004 Mark Adler
33
* For conditions of distribution and use, see copyright notice in zlib.h
44
*/
55

@@ -12,12 +12,13 @@
1212
#define NMAX 5552
1313
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
1414

15-
#define DO1(buf,i) {s1 += buf[i]; s2 += s1;}
15+
#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
1616
#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
1717
#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
1818
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
1919
#define DO16(buf) DO8(buf,0); DO8(buf,8);
2020

21+
/* use NO_DIVIDE if your processor does not do division in hardware */
2122
#ifdef NO_DIVIDE
2223
# define MOD(a) \
2324
do { \
@@ -39,8 +40,17 @@
3940
if (a >= (BASE << 1)) a -= (BASE << 1); \
4041
if (a >= BASE) a -= BASE; \
4142
} while (0)
43+
# define MOD4(a) \
44+
do { \
45+
if (a >= (BASE << 4)) a -= (BASE << 4); \
46+
if (a >= (BASE << 3)) a -= (BASE << 3); \
47+
if (a >= (BASE << 2)) a -= (BASE << 2); \
48+
if (a >= (BASE << 1)) a -= (BASE << 1); \
49+
if (a >= BASE) a -= BASE; \
50+
} while (0)
4251
#else
4352
# define MOD(a) a %= BASE
53+
# define MOD4(a) a %= BASE
4454
#endif
4555

4656
/* ========================================================================= */
@@ -49,26 +59,91 @@ uLong ZEXPORT adler32(adler, buf, len)
4959
const Bytef *buf;
5060
uInt len;
5161
{
52-
unsigned long s1 = adler & 0xffff;
53-
unsigned long s2 = (adler >> 16) & 0xffff;
54-
int k;
62+
unsigned long sum2;
63+
unsigned n;
64+
65+
/* split Adler-32 into component sums */
66+
sum2 = (adler >> 16) & 0xffff;
67+
adler &= 0xffff;
68+
69+
/* in case user likes doing a byte at a time, keep it fast */
70+
if (len == 1) {
71+
adler += buf[0];
72+
if (adler >= BASE)
73+
adler -= BASE;
74+
sum2 += adler;
75+
if (sum2 >= BASE)
76+
sum2 -= BASE;
77+
return adler | (sum2 << 16);
78+
}
5579

56-
if (buf == Z_NULL) return 1L;
80+
/* initial Adler-32 value (deferred check for len == 1 speed) */
81+
if (buf == Z_NULL)
82+
return 1L;
5783

58-
while (len > 0) {
59-
k = len < NMAX ? (int)len : NMAX;
60-
len -= k;
61-
while (k >= 16) {
84+
/* in case short lengths are provided, keep it somewhat fast */
85+
if (len < 16) {
86+
while (len--) {
87+
adler += *buf++;
88+
sum2 += adler;
89+
}
90+
if (adler >= BASE)
91+
adler -= BASE;
92+
MOD4(sum2); /* only added so many BASE's */
93+
return adler | (sum2 << 16);
94+
}
95+
96+
/* do length NMAX blocks -- requires just one modulo operation */
97+
while (len >= NMAX) {
98+
len -= NMAX;
99+
n = NMAX / 16; /* NMAX is divisible by 16 */
100+
do {
101+
DO16(buf); /* 16 sums unrolled */
102+
buf += 16;
103+
} while (--n);
104+
MOD(adler);
105+
MOD(sum2);
106+
}
107+
108+
/* do remaining bytes (less than NMAX, still just one modulo) */
109+
if (len) { /* avoid modulos if none remaining */
110+
while (len >= 16) {
111+
len -= 16;
62112
DO16(buf);
63113
buf += 16;
64-
k -= 16;
65114
}
66-
if (k != 0) do {
67-
s1 += *buf++;
68-
s2 += s1;
69-
} while (--k);
70-
MOD(s1);
71-
MOD(s2);
115+
while (len--) {
116+
adler += *buf++;
117+
sum2 += adler;
118+
}
119+
MOD(adler);
120+
MOD(sum2);
72121
}
73-
return (s2 << 16) | s1;
122+
123+
/* return recombined sums */
124+
return adler | (sum2 << 16);
125+
}
126+
127+
/* ========================================================================= */
128+
uLong ZEXPORT adler32_combine(adler1, adler2, len2)
129+
uLong adler1;
130+
uLong adler2;
131+
z_off_t len2;
132+
{
133+
unsigned long sum1;
134+
unsigned long sum2;
135+
unsigned rem;
136+
137+
/* the derivation of this formula is left as an exercise for the reader */
138+
rem = (unsigned)(len2 % BASE);
139+
sum1 = adler1 & 0xffff;
140+
sum2 = rem * sum1;
141+
MOD(sum2);
142+
sum1 += (adler2 & 0xffff) + BASE - 1;
143+
sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
144+
if (sum1 > BASE) sum1 -= BASE;
145+
if (sum1 > BASE) sum1 -= BASE;
146+
if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
147+
if (sum2 > BASE) sum2 -= BASE;
148+
return sum1 | (sum2 << 16);
74149
}

zlib/compress.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* compress.c -- compress a memory buffer
2-
* Copyright (C) 1995-2002 Jean-loup Gailly.
2+
* Copyright (C) 1995-2003 Jean-loup Gailly.
33
* For conditions of distribution and use, see copyright notice in zlib.h
44
*/
55

0 commit comments

Comments
 (0)