Skip to content

Commit 0484693

Browse files
committed
zlib 1.2.2.2
1 parent 9811b53 commit 0484693

39 files changed

+2178
-177
lines changed

ChangeLog

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11

22
ChangeLog file for zlib
33

4+
Changes in 1.2.2.2 (30 December 2004)
5+
- Replace structure assignments in deflate.c and inflate.c with zmemcpy to
6+
avoid implicit memcpy calls (portability for no-library compilation)
7+
- Increase sprintf() buffer size in gzdopen() to allow for large numbers
8+
- Add INFLATE_STRICT to check distances against zlib header
9+
- Improve WinCE errno handling and comments [Chang]
10+
- Remove comment about no gzip header processing in FAQ
11+
- Add Z_FIXED strategy option to deflateInit2() to force fixed trees
12+
- Add updated make_vms.com [Coghlan], update README
13+
- Create a new "examples" directory, move gzappend.c there, add zpipe.c,
14+
fitblk.c, gzlog.[ch], gzjoin.c, and zlib_how.html.
15+
- Add FAQ entry and comments in deflate.c on uninitialized memory access
16+
- Add Solaris 9 make options in configure [Gilbert]
17+
- Allow strerror() usage in gzio.c for STDC
18+
- Fix DecompressBuf in contrib/delphi/ZLib.pas [ManChesTer]
19+
- Update contrib/masmx86/inffas32.asm and gvmat32.asm [Vollant]
20+
- Use z_off_t for adler32_combine() and crc32_combine() lengths
21+
- Make adler32() much faster for small len
22+
- Use OS_CODE in deflate() default gzip header
23+
424
Changes in 1.2.2.1 (31 October 2004)
525
- Allow inflateSetDictionary() call for raw inflate
626
- Fix inflate header crc check bug for file names and comments
@@ -20,6 +40,7 @@ Changes in 1.2.2.1 (31 October 2004)
2040
- Do not define an exit() prototype in zutil.c unless DEBUG defined
2141
- Remove prototype of exit() from zutil.c, example.c, minigzip.c [Truta]
2242
- Add comment in zlib.h for Z_NO_FLUSH parameter to deflate()
43+
- Fix Darwin build version identification [Peterson]
2344

2445
Changes in 1.2.2 (3 October 2004)
2546
- Update zlib.h comments on gzip in-memory processing

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.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ CPP=$(CC) -E
3030

3131
LIBS=libz.a
3232
SHAREDLIB=libz.so
33-
SHAREDLIBV=libz.so.1.2.2.1
33+
SHAREDLIBV=libz.so.1.2.2.2
3434
SHAREDLIBM=libz.so.1
3535

3636
AR=ar rc

Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ CPP=$(CC) -E
3030

3131
LIBS=libz.a
3232
SHAREDLIB=libz.so
33-
SHAREDLIBV=libz.so.1.2.2.1
33+
SHAREDLIBV=libz.so.1.2.2.2
3434
SHAREDLIBM=libz.so.1
3535

3636
AR=ar rc

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.1 is a general purpose data compression library. All the code is
3+
zlib 1.2.2.2 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.1 are documented in the file ChangeLog.
36+
The changes made in version 1.2.2.2 are documented in the file ChangeLog.
3837

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

adler32.c

Lines changed: 84 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -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,48 +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);
74125
}
75126

76127
/* ========================================================================= */
77128
uLong ZEXPORT adler32_combine(adler1, adler2, len2)
78129
uLong adler1;
79130
uLong adler2;
80-
uLong len2;
131+
z_off_t len2;
81132
{
82-
unsigned long s1;
83-
unsigned long s2;
133+
unsigned long sum1;
134+
unsigned long sum2;
135+
unsigned rem;
84136

85-
len2 %= BASE;
86-
s1 = adler1 & 0xffff;
87-
s2 = len2 * s1;
88-
MOD(s2);
89-
s1 += (adler2 & 0xffff) + BASE - 1;
90-
s2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - len2;
91-
if (s1 > BASE) s1 -= BASE;
92-
if (s1 > BASE) s1 -= BASE;
93-
if (s2 > (BASE << 1)) s2 -= (BASE << 1);
94-
if (s2 > BASE) s2 -= BASE;
95-
return (s2 << 16) | s1;
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);
96149
}

as400/zlib.inc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
* ZLIB.INC - Interface to the general purpose compression library
22
*
33
* ILE RPG400 version by Patrick Monnerat, DATASPHERE.
4-
* Version 1.2.2.1
4+
* Version 1.2.2.2
55
*
66
*
77
* WARNING:
@@ -20,8 +20,8 @@
2020
* Constants
2121
**************************************************************************
2222
*
23-
D ZLIB_VERSION C '1.2.2.1' Header's version
24-
D ZLIB_VERNUM C X'1221'
23+
D ZLIB_VERSION C '1.2.2.2' Header's version
24+
D ZLIB_VERNUM C X'1222'
2525
*
2626
D Z_NO_FLUSH C 0
2727
D Z_SYNC_FLUSH C 2

configure

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ if test "$gcc" -eq 1 && ($cc -c $cflags $test.c) 2>/dev/null; then
8989
SHAREDLIB=libz$shared_ext
9090
SHAREDLIBV=libz.$VER$shared_ext
9191
SHAREDLIBM=libz.$VER1$shared_ext
92-
LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBV -compatibility_version $VER2 -current_version $VER"};;
92+
LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBM -compatibility_version $VER1 -current_version $VER"};;
9393
*) LDSHARED=${LDSHARED-"$cc -shared"};;
9494
esac
9595
else
@@ -125,6 +125,9 @@ else
125125
SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"}
126126
CFLAGS=${CFLAGS-"-O2"}
127127
LDSHARED=${LDSHARED-"ld"};;
128+
SunStudio\ 9*) SFLAGS=${CFLAGS-"-DUSE_MMAP -fast -xcode=pic32 -xtarget=ultra3 -xarch=v9b"}
129+
CFLAGS=${CFLAGS-"-DUSE_MMAP -fast -xtarget=ultra3 -xarch=v9b"}
130+
LDSHARED=${LDSHARED-"cc -xarch=v9b"};;
128131
UNIX_System_V\ 4.2.0)
129132
SFLAGS=${CFLAGS-"-KPIC -O"}
130133
CFLAGS=${CFLAGS-"-O"}

contrib/README.contrib

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ delphi/ by Cosmin Truta <[email protected]>
2222
dotzlib/ by Henrik Ravn <[email protected]>
2323
Support for Microsoft .Net and Visual C++ .Net
2424

25-
gzappend/ by Mark Adler <[email protected]>
26-
append to a gzip file -- illustrates the use of Z_BLOCK
27-
2825
infback9/ by Mark Adler <[email protected]>
2926
Unsupported diffs to infback to decode the deflate64 format
3027

contrib/delphi/ZLib.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ procedure DecompressBuf(const InBuf: Pointer; InBytes: Integer;
344344
strm.avail_out := OutBytes;
345345
DCheck(inflateInit_(strm, zlib_version, sizeof(strm)));
346346
try
347-
while DCheck(inflate(strm, Z_FINISH)) <> Z_STREAM_END do
347+
while DCheck(inflate(strm, Z_NO_FLUSH)) <> Z_STREAM_END do
348348
begin
349349
P := OutBuf;
350350
Inc(OutBytes, BufInc);

contrib/infback9/inftree9.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#define MAXBITS 15
1010

1111
const char inflate9_copyright[] =
12-
" inflate9 1.2.2.1 Copyright 1995-2004 Mark Adler ";
12+
" inflate9 1.2.2.2 Copyright 1995-2004 Mark Adler ";
1313
/*
1414
If you use the zlib library in a product, an acknowledgment is welcome
1515
in the documentation of your product. If for some reason you cannot
@@ -64,7 +64,7 @@ unsigned short FAR *work;
6464
static const unsigned short lext[31] = { /* Length codes 257..285 extra */
6565
128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129,
6666
130, 130, 130, 130, 131, 131, 131, 131, 132, 132, 132, 132,
67-
133, 133, 133, 133, 144, 77, 207};
67+
133, 133, 133, 133, 144, 72, 199};
6868
static const unsigned short dbase[32] = { /* Distance codes 0..31 base */
6969
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49,
7070
65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073,

0 commit comments

Comments
 (0)