Skip to content

Commit

Permalink
zlib 1.2.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
madler committed Sep 10, 2011
1 parent 9811b53 commit 0484693
Show file tree
Hide file tree
Showing 39 changed files with 2,178 additions and 177 deletions.
21 changes: 21 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@

ChangeLog file for zlib

Changes in 1.2.2.2 (30 December 2004)
- Replace structure assignments in deflate.c and inflate.c with zmemcpy to
avoid implicit memcpy calls (portability for no-library compilation)
- Increase sprintf() buffer size in gzdopen() to allow for large numbers
- Add INFLATE_STRICT to check distances against zlib header
- Improve WinCE errno handling and comments [Chang]
- Remove comment about no gzip header processing in FAQ
- Add Z_FIXED strategy option to deflateInit2() to force fixed trees
- Add updated make_vms.com [Coghlan], update README
- Create a new "examples" directory, move gzappend.c there, add zpipe.c,
fitblk.c, gzlog.[ch], gzjoin.c, and zlib_how.html.
- Add FAQ entry and comments in deflate.c on uninitialized memory access
- Add Solaris 9 make options in configure [Gilbert]
- Allow strerror() usage in gzio.c for STDC
- Fix DecompressBuf in contrib/delphi/ZLib.pas [ManChesTer]
- Update contrib/masmx86/inffas32.asm and gvmat32.asm [Vollant]
- Use z_off_t for adler32_combine() and crc32_combine() lengths
- Make adler32() much faster for small len
- Use OS_CODE in deflate() default gzip header

Changes in 1.2.2.1 (31 October 2004)
- Allow inflateSetDictionary() call for raw inflate
- Fix inflate header crc check bug for file names and comments
Expand All @@ -20,6 +40,7 @@ Changes in 1.2.2.1 (31 October 2004)
- Do not define an exit() prototype in zutil.c unless DEBUG defined
- Remove prototype of exit() from zutil.c, example.c, minigzip.c [Truta]
- Add comment in zlib.h for Z_NO_FLUSH parameter to deflate()
- Fix Darwin build version identification [Peterson]

Changes in 1.2.2 (3 October 2004)
- Update zlib.h comments on gzip in-memory processing
Expand Down
26 changes: 14 additions & 12 deletions FAQ
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,6 @@ The lastest zlib FAQ is at http://www.gzip.org/zlib/zlib_faq.html
format using deflateInit2(). You can also request that inflate decode
the gzip format using inflateInit2(). Read zlib.h for more details.

Note that you cannot specify special gzip header contents (e.g. a file
name or modification date), nor will inflate tell you what was in the
gzip header. If you need to customize the header or see what's in it,
you can use the raw deflate and inflate operations and the crc32()
function and roll your own gzip encoding and decoding. Read the gzip
RFC 1952 for details of the header and trailer format.

21. Is zlib thread-safe?

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

36. Will zlib read the (insert any ancient or arcane format here) compressed
36. Valgrind (or some similar memory access checker) says that deflate is
performing a conditional jump that depends on an uninitialized value.
Isn't that a bug?

No. That is intentional for performance reasons, and the output of
deflate is not affected. This only started showing up recently since
zlib 1.2.x uses malloc() by default for allocations, whereas earlier
versions used calloc(), which zeros out the allocated memory.

37. Will zlib read the (insert any ancient or arcane format here) compressed
data format?

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

37. How can I encrypt/decrypt zip files with zlib?
38. How can I encrypt/decrypt zip files with zlib?

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

38. What's the difference between the "gzip" and "deflate" HTTP 1.1 encodings?
39. What's the difference between the "gzip" and "deflate" HTTP 1.1 encodings?

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

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

39. Does zlib support the new "Deflate64" format introduced by PKWare?
40. Does zlib support the new "Deflate64" format introduced by PKWare?

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

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

No. Go away. Shoo.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ CPP=$(CC) -E

LIBS=libz.a
SHAREDLIB=libz.so
SHAREDLIBV=libz.so.1.2.2.1
SHAREDLIBV=libz.so.1.2.2.2
SHAREDLIBM=libz.so.1

AR=ar rc
Expand Down
2 changes: 1 addition & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ CPP=$(CC) -E

LIBS=libz.a
SHAREDLIB=libz.so
SHAREDLIBV=libz.so.1.2.2.1
SHAREDLIBV=libz.so.1.2.2.2
SHAREDLIBM=libz.so.1

AR=ar rc
Expand Down
9 changes: 4 additions & 5 deletions README
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ZLIB DATA COMPRESSION LIBRARY

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

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

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

The changes made in version 1.2.2.1 are documented in the file ChangeLog.
The changes made in version 1.2.2.2 are documented in the file ChangeLog.

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

Expand Down
115 changes: 84 additions & 31 deletions adler32.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
#define NMAX 5552
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */

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

/* use NO_DIVIDE if your processor does not do division in hardware */
#ifdef NO_DIVIDE
# define MOD(a) \
do { \
Expand All @@ -39,8 +40,17 @@
if (a >= (BASE << 1)) a -= (BASE << 1); \
if (a >= BASE) a -= BASE; \
} while (0)
# define MOD4(a) \
do { \
if (a >= (BASE << 4)) a -= (BASE << 4); \
if (a >= (BASE << 3)) a -= (BASE << 3); \
if (a >= (BASE << 2)) a -= (BASE << 2); \
if (a >= (BASE << 1)) a -= (BASE << 1); \
if (a >= BASE) a -= BASE; \
} while (0)
#else
# define MOD(a) a %= BASE
# define MOD4(a) a %= BASE
#endif

/* ========================================================================= */
Expand All @@ -49,48 +59,91 @@ uLong ZEXPORT adler32(adler, buf, len)
const Bytef *buf;
uInt len;
{
unsigned long s1 = adler & 0xffff;
unsigned long s2 = (adler >> 16) & 0xffff;
int k;
unsigned long sum2;
unsigned n;

/* split Adler-32 into component sums */
sum2 = (adler >> 16) & 0xffff;
adler &= 0xffff;

/* in case user likes doing a byte at a time, keep it fast */
if (len == 1) {
adler += buf[0];
if (adler >= BASE)
adler -= BASE;
sum2 += adler;
if (sum2 >= BASE)
sum2 -= BASE;
return adler | (sum2 << 16);
}

if (buf == Z_NULL) return 1L;
/* initial Adler-32 value (deferred check for len == 1 speed) */
if (buf == Z_NULL)
return 1L;

while (len > 0) {
k = len < NMAX ? (int)len : NMAX;
len -= k;
while (k >= 16) {
/* in case short lengths are provided, keep it somewhat fast */
if (len < 16) {
while (len--) {
adler += *buf++;
sum2 += adler;
}
if (adler >= BASE)
adler -= BASE;
MOD4(sum2); /* only added so many BASE's */
return adler | (sum2 << 16);
}

/* do length NMAX blocks -- requires just one modulo operation */
while (len >= NMAX) {
len -= NMAX;
n = NMAX / 16; /* NMAX is divisible by 16 */
do {
DO16(buf); /* 16 sums unrolled */
buf += 16;
} while (--n);
MOD(adler);
MOD(sum2);
}

/* do remaining bytes (less than NMAX, still just one modulo) */
if (len) { /* avoid modulos if none remaining */
while (len >= 16) {
len -= 16;
DO16(buf);
buf += 16;
k -= 16;
}
if (k != 0) do {
s1 += *buf++;
s2 += s1;
} while (--k);
MOD(s1);
MOD(s2);
while (len--) {
adler += *buf++;
sum2 += adler;
}
MOD(adler);
MOD(sum2);
}
return (s2 << 16) | s1;

/* return recombined sums */
return adler | (sum2 << 16);
}

/* ========================================================================= */
uLong ZEXPORT adler32_combine(adler1, adler2, len2)
uLong adler1;
uLong adler2;
uLong len2;
z_off_t len2;
{
unsigned long s1;
unsigned long s2;
unsigned long sum1;
unsigned long sum2;
unsigned rem;

len2 %= BASE;
s1 = adler1 & 0xffff;
s2 = len2 * s1;
MOD(s2);
s1 += (adler2 & 0xffff) + BASE - 1;
s2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - len2;
if (s1 > BASE) s1 -= BASE;
if (s1 > BASE) s1 -= BASE;
if (s2 > (BASE << 1)) s2 -= (BASE << 1);
if (s2 > BASE) s2 -= BASE;
return (s2 << 16) | s1;
/* the derivation of this formula is left as an exercise for the reader */
rem = (unsigned)(len2 % BASE);
sum1 = adler1 & 0xffff;
sum2 = rem * sum1;
MOD(sum2);
sum1 += (adler2 & 0xffff) + BASE - 1;
sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
if (sum1 > BASE) sum1 -= BASE;
if (sum1 > BASE) sum1 -= BASE;
if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
if (sum2 > BASE) sum2 -= BASE;
return sum1 | (sum2 << 16);
}
6 changes: 3 additions & 3 deletions as400/zlib.inc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
* ZLIB.INC - Interface to the general purpose compression library
*
* ILE RPG400 version by Patrick Monnerat, DATASPHERE.
* Version 1.2.2.1
* Version 1.2.2.2
*
*
* WARNING:
Expand All @@ -20,8 +20,8 @@
* Constants
**************************************************************************
*
D ZLIB_VERSION C '1.2.2.1' Header's version
D ZLIB_VERNUM C X'1221'
D ZLIB_VERSION C '1.2.2.2' Header's version
D ZLIB_VERNUM C X'1222'
*
D Z_NO_FLUSH C 0
D Z_SYNC_FLUSH C 2
Expand Down
5 changes: 4 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ if test "$gcc" -eq 1 && ($cc -c $cflags $test.c) 2>/dev/null; then
SHAREDLIB=libz$shared_ext
SHAREDLIBV=libz.$VER$shared_ext
SHAREDLIBM=libz.$VER1$shared_ext
LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBV -compatibility_version $VER2 -current_version $VER"};;
LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBM -compatibility_version $VER1 -current_version $VER"};;
*) LDSHARED=${LDSHARED-"$cc -shared"};;
esac
else
Expand Down Expand Up @@ -125,6 +125,9 @@ else
SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"}
CFLAGS=${CFLAGS-"-O2"}
LDSHARED=${LDSHARED-"ld"};;
SunStudio\ 9*) SFLAGS=${CFLAGS-"-DUSE_MMAP -fast -xcode=pic32 -xtarget=ultra3 -xarch=v9b"}
CFLAGS=${CFLAGS-"-DUSE_MMAP -fast -xtarget=ultra3 -xarch=v9b"}
LDSHARED=${LDSHARED-"cc -xarch=v9b"};;
UNIX_System_V\ 4.2.0)
SFLAGS=${CFLAGS-"-KPIC -O"}
CFLAGS=${CFLAGS-"-O"}
Expand Down
3 changes: 0 additions & 3 deletions contrib/README.contrib
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ delphi/ by Cosmin Truta <[email protected]>
dotzlib/ by Henrik Ravn <[email protected]>
Support for Microsoft .Net and Visual C++ .Net

gzappend/ by Mark Adler <[email protected]>
append to a gzip file -- illustrates the use of Z_BLOCK

infback9/ by Mark Adler <[email protected]>
Unsupported diffs to infback to decode the deflate64 format

Expand Down
2 changes: 1 addition & 1 deletion contrib/delphi/ZLib.pas
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ procedure DecompressBuf(const InBuf: Pointer; InBytes: Integer;
strm.avail_out := OutBytes;
DCheck(inflateInit_(strm, zlib_version, sizeof(strm)));
try
while DCheck(inflate(strm, Z_FINISH)) <> Z_STREAM_END do
while DCheck(inflate(strm, Z_NO_FLUSH)) <> Z_STREAM_END do
begin
P := OutBuf;
Inc(OutBytes, BufInc);
Expand Down
4 changes: 2 additions & 2 deletions contrib/infback9/inftree9.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define MAXBITS 15

const char inflate9_copyright[] =
" inflate9 1.2.2.1 Copyright 1995-2004 Mark Adler ";
" inflate9 1.2.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
Expand Down Expand Up @@ -64,7 +64,7 @@ unsigned short FAR *work;
static const unsigned short lext[31] = { /* Length codes 257..285 extra */
128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129,
130, 130, 130, 130, 131, 131, 131, 131, 132, 132, 132, 132,
133, 133, 133, 133, 144, 77, 207};
133, 133, 133, 133, 144, 72, 199};
static const unsigned short dbase[32] = { /* Distance codes 0..31 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,
Expand Down
Loading

0 comments on commit 0484693

Please sign in to comment.