Skip to content

Commit 086e982

Browse files
committed
zlib 1.2.0.4
1 parent 85e7d7d commit 086e982

20 files changed

+335
-92
lines changed

ChangeLog

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11

22
ChangeLog file for zlib
3+
Changes in 1.2.0.4 (10 August 2003)
4+
- Minor FAQ updates
5+
- Be more strict when checking inflateInit2's windowBits parameter
6+
- Change NO_GUNZIP compile option to NO_GZIP to cover deflate as well
7+
- Add gzip wrapper option to deflateInit2 using windowBits
8+
- Add updated QNX rule in configure and qnx directory [Bonnefoy]
9+
- Make inflate distance-too-far checks more rigorous
10+
- Clean up FAR usage in inflate
11+
- Add casting to sizeof() in gzio.c and minigzip.c
12+
313
Changes in 1.2.0.3 (19 July 2003)
414
- Fix silly error in gzungetc() implementation [Vollant]
515
- Update contrib/minizip and contrib/vstudio [Vollant]

FAQ

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,16 @@ The lastest zlib FAQ is at http://www.gzip.org/zlib/zlib_faq.html
122122

123123
18. Well that's nice, but how do I make a gzip file in memory?
124124

125-
Read RFC 1952 for the gzip header and trailer format, and roll your own
126-
gzip formatted data using raw deflate and crc32().
125+
You can request that deflate write the gzip format instead of the zlib
126+
format using deflateInit2(). You can also request that inflate decode
127+
the gzip format using inflateInit2(). Read zlib.h for more details.
128+
129+
Note that you cannot specify special gzip header contents (e.g. a file
130+
name or modification date), nor will inflate tell you what was in the
131+
gzip header. If you need to customize the header or see what's in it,
132+
you can use the raw deflate and inflate operations and the crc32()
133+
function and roll your own gzip encoding and decoding. Read the gzip
134+
RFC 1952 for details of the header and trailer format.
127135

128136
19. Is zlib thread-safe?
129137

@@ -253,7 +261,7 @@ The lastest zlib FAQ is at http://www.gzip.org/zlib/zlib_faq.html
253261
32. Is there a Java version of zlib?
254262

255263
Probably what you want is to use zlib in Java. zlib is already included
256-
as part of the Java SDK in the java.util.zip class. If you really want
264+
as part of the Java SDK in the java.util.zip package. If you really want
257265
a version of zlib written in the Java language, look on the zlib home
258266
page for links: http://www.zlib.org/
259267

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ LDFLAGS=libz.a
2424
LDSHARED=$(CC)
2525
CPP=$(CC) -E
2626

27-
VER=1.2.0.3
27+
VER=1.2.0.4
2828
LIBS=libz.a
2929
SHAREDLIB=libz.so
3030

Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ LDFLAGS=libz.a
2424
LDSHARED=$(CC)
2525
CPP=$(CC) -E
2626

27-
VER=1.2.0.3
27+
VER=1.2.0.4
2828
LIBS=libz.a
2929
SHAREDLIB=libz.so
3030

README

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

3-
zlib 1.2.0.3 is a general purpose data compression library. All the code is
3+
zlib 1.2.0.4 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)
@@ -34,7 +34,7 @@ Mark Nelson <[email protected]> wrote an article about zlib for the Jan. 1997
3434
issue of Dr. Dobb's Journal; a copy of the article is available in
3535
http://dogma.net/markn/articles/zlibtool/zlibtool.htm
3636

37-
The changes made in version 1.2.0.3 are documented in the file ChangeLog.
37+
The changes made in version 1.2.0.4 are documented in the file ChangeLog.
3838

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

configure

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ if test "$gcc" -eq 1 && ($cc -c $cflags $test.c) 2>/dev/null; then
7878
CFLAGS="$cflags"
7979
case `(uname -s || echo unknown) 2>/dev/null` in
8080
Linux | linux) LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1"};;
81+
QNX*) #This is for QNX6. I suppose that the QNX rule below is for QNX2,QNX4 ([email protected])
82+
LDSHARED=${LDSHARED-"$cc -shared -Wl,-hlibz.so.1"};;
8183
HP-UX*) LDSHARED=${LDSHARED-"$cc -shared $SFLAGS"}
8284
shared_ext='.sl'
8385
SHAREDLIB='libz.sl';;

crc32.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# endif /* !DYNAMIC_CRC_TABLE */
1919
#endif /* MAKECRCH */
2020

21-
#include "zutil.h"
21+
#include "zutil.h" /* for STDC and FAR definitions */
2222

2323
#define local static
2424

deflate.c

Lines changed: 99 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
#include "deflate.h"
5353

5454
const char deflate_copyright[] =
55-
" deflate 1.2.0.3 Copyright 1995-2003 Jean-loup Gailly ";
55+
" deflate 1.2.0.4 Copyright 1995-2003 Jean-loup Gailly ";
5656
/*
5757
If you use the zlib library in a product, an acknowledgment is welcome
5858
in the documentation of your product. If for some reason you cannot
@@ -132,12 +132,12 @@ typedef struct config_s {
132132
local const config configuration_table[2] = {
133133
/* good lazy nice chain */
134134
/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */
135-
/* 1 */ {4, 4, 8, 4, deflate_fast}}; /* maximum speed, no lazy matches */
135+
/* 1 */ {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */
136136
#else
137137
local const config configuration_table[10] = {
138138
/* good lazy nice chain */
139139
/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */
140-
/* 1 */ {4, 4, 8, 4, deflate_fast}, /* maximum speed, no lazy matches */
140+
/* 1 */ {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */
141141
/* 2 */ {4, 5, 16, 8, deflate_fast},
142142
/* 3 */ {4, 6, 32, 32, deflate_fast},
143143

@@ -146,7 +146,7 @@ local const config configuration_table[10] = {
146146
/* 6 */ {8, 16, 128, 128, deflate_slow},
147147
/* 7 */ {8, 32, 128, 256, deflate_slow},
148148
/* 8 */ {32, 128, 258, 1024, deflate_slow},
149-
/* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* maximum compression */
149+
/* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* max compression */
150150
#endif
151151

152152
/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4
@@ -225,7 +225,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
225225
int stream_size;
226226
{
227227
deflate_state *s;
228-
int noheader = 0;
228+
int wrap = 1;
229229
static const char my_version[] = ZLIB_VERSION;
230230

231231
ushf *overlay;
@@ -252,10 +252,16 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
252252
if (level == Z_DEFAULT_COMPRESSION) level = 6;
253253
#endif
254254

255-
if (windowBits < 0) { /* undocumented feature: suppress zlib header */
256-
noheader = 1;
255+
if (windowBits < 0) { /* suppress zlib wrapper */
256+
wrap = 0;
257257
windowBits = -windowBits;
258258
}
259+
#ifdef GZIP
260+
else if (windowBits > 15) {
261+
wrap = 2; /* write gzip wrapper instead */
262+
windowBits -= 16;
263+
}
264+
#endif
259265
if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
260266
windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
261267
strategy < 0 || strategy > Z_RLE) {
@@ -267,7 +273,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
267273
strm->state = (struct internal_state FAR *)s;
268274
s->strm = strm;
269275

270-
s->noheader = noheader;
276+
s->wrap = wrap;
271277
s->w_bits = windowBits;
272278
s->w_size = 1 << s->w_bits;
273279
s->w_mask = s->w_size - 1;
@@ -316,11 +322,12 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
316322
IPos hash_head = 0;
317323

318324
if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
319-
(!strm->state->noheader && strm->state->status != INIT_STATE))
325+
strm->state->wrap == 2 ||
326+
(strm->state->wrap == 1 && strm->state->status != INIT_STATE))
320327
return Z_STREAM_ERROR;
321328

322329
s = strm->state;
323-
if (!s->noheader)
330+
if (s->wrap)
324331
strm->adler = adler32(strm->adler, dictionary, dictLength);
325332

326333
if (length < MIN_MATCH) return Z_OK;
@@ -364,11 +371,15 @@ int ZEXPORT deflateReset (strm)
364371
s->pending = 0;
365372
s->pending_out = s->pending_buf;
366373

367-
if (s->noheader < 0) {
368-
s->noheader = 0; /* was set to -1 by deflate(..., Z_FINISH); */
374+
if (s->wrap < 0) {
375+
s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
369376
}
370-
s->status = s->noheader ? BUSY_STATE : INIT_STATE;
371-
strm->adler = 1;
377+
s->status = s->wrap ? INIT_STATE : BUSY_STATE;
378+
strm->adler =
379+
#ifdef GZIP
380+
s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
381+
#endif
382+
adler32(0L, Z_NULL, 0);
372383
s->last_flush = Z_NO_FLUSH;
373384

374385
_tr_init(s);
@@ -428,7 +439,7 @@ int ZEXPORT deflateParams(strm, level, strategy)
428439
* can emit on compressed data for some combinations of the parameters.
429440
*
430441
* This function could be more sophisticated to provide closer upper bounds
431-
* for every combination of windowBits and memLevel, as well as noheader.
442+
* for every combination of windowBits and memLevel, as well as wrap.
432443
* But even the conservative upper bound of about 14% expansion does not
433444
* seem onerous for output buffer allocation.
434445
*/
@@ -519,33 +530,53 @@ int ZEXPORT deflate (strm, flush)
519530
old_flush = s->last_flush;
520531
s->last_flush = flush;
521532

522-
/* Write the zlib header */
533+
/* Write the header */
523534
if (s->status == INIT_STATE) {
524-
525-
uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
526-
uInt level_flags;
527-
528-
if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
529-
level_flags = 0;
530-
else if (s->level < 6)
531-
level_flags = 1;
532-
else if (s->level == 6)
533-
level_flags = 2;
535+
#ifdef GZIP
536+
if (s->wrap == 2) {
537+
put_byte(s, 31);
538+
put_byte(s, 139);
539+
put_byte(s, 8);
540+
put_byte(s, 0);
541+
put_byte(s, 0);
542+
put_byte(s, 0);
543+
put_byte(s, 0);
544+
put_byte(s, 0);
545+
put_byte(s, s->level == 9 ? 2 :
546+
(s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
547+
4 : 0));
548+
put_byte(s, 255);
549+
s->status = BUSY_STATE;
550+
strm->adler = crc32(0L, Z_NULL, 0);
551+
}
534552
else
535-
level_flags = 3;
536-
header |= (level_flags << 6);
537-
if (s->strstart != 0) header |= PRESET_DICT;
538-
header += 31 - (header % 31);
539-
540-
s->status = BUSY_STATE;
541-
putShortMSB(s, header);
542-
543-
/* Save the adler32 of the preset dictionary: */
544-
if (s->strstart != 0) {
545-
putShortMSB(s, (uInt)(strm->adler >> 16));
546-
putShortMSB(s, (uInt)(strm->adler & 0xffff));
553+
#endif
554+
{
555+
uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
556+
uInt level_flags;
557+
558+
if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
559+
level_flags = 0;
560+
else if (s->level < 6)
561+
level_flags = 1;
562+
else if (s->level == 6)
563+
level_flags = 2;
564+
else
565+
level_flags = 3;
566+
header |= (level_flags << 6);
567+
if (s->strstart != 0) header |= PRESET_DICT;
568+
header += 31 - (header % 31);
569+
570+
s->status = BUSY_STATE;
571+
putShortMSB(s, header);
572+
573+
/* Save the adler32 of the preset dictionary: */
574+
if (s->strstart != 0) {
575+
putShortMSB(s, (uInt)(strm->adler >> 16));
576+
putShortMSB(s, (uInt)(strm->adler & 0xffff));
577+
}
578+
strm->adler = adler32(0L, Z_NULL, 0);
547579
}
548-
strm->adler = 1L;
549580
}
550581

551582
/* Flush as much pending output as possible */
@@ -622,16 +653,31 @@ int ZEXPORT deflate (strm, flush)
622653
Assert(strm->avail_out > 0, "bug2");
623654

624655
if (flush != Z_FINISH) return Z_OK;
625-
if (s->noheader) return Z_STREAM_END;
626-
627-
/* Write the zlib trailer (adler32) */
628-
putShortMSB(s, (uInt)(strm->adler >> 16));
629-
putShortMSB(s, (uInt)(strm->adler & 0xffff));
656+
if (s->wrap <= 0) return Z_STREAM_END;
657+
658+
/* Write the trailer */
659+
#ifdef GZIP
660+
if (s->wrap == 2) {
661+
put_byte(s, (Byte)(strm->adler & 0xff));
662+
put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
663+
put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
664+
put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
665+
put_byte(s, (Byte)(strm->total_in & 0xff));
666+
put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
667+
put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
668+
put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
669+
}
670+
else
671+
#endif
672+
{
673+
putShortMSB(s, (uInt)(strm->adler >> 16));
674+
putShortMSB(s, (uInt)(strm->adler & 0xffff));
675+
}
630676
flush_pending(strm);
631677
/* If avail_out is zero, the application will call deflate again
632678
* to flush the rest.
633679
*/
634-
s->noheader = -1; /* write the trailer only once! */
680+
if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
635681
return s->pending != 0 ? Z_OK : Z_STREAM_END;
636682
}
637683

@@ -740,9 +786,14 @@ local int read_buf(strm, buf, size)
740786

741787
strm->avail_in -= len;
742788

743-
if (!strm->state->noheader) {
789+
if (strm->state->wrap == 1) {
744790
strm->adler = adler32(strm->adler, strm->next_in, len);
745791
}
792+
#ifdef GZIP
793+
else if (strm->state->wrap == 2) {
794+
strm->adler = crc32(strm->adler, strm->next_in, len);
795+
}
796+
#endif
746797
zmemcpy(buf, strm->next_in, len);
747798
strm->next_in += len;
748799
strm->total_in += len;
@@ -1044,7 +1095,7 @@ local void fill_window(s)
10441095

10451096
} else if (more == (unsigned)(-1)) {
10461097
/* Very unlikely, but possible on 16 bit machine if
1047-
* strstart == 0 && lookahead == 1 (input done one byte at time)
1098+
* strstart == 0 && lookahead == 1 (input done a byte at time)
10481099
*/
10491100
more--;
10501101
}
@@ -1271,7 +1322,7 @@ local block_state deflate_fast(s, flush)
12711322
#ifndef FASTEST
12721323
if (s->match_length <= s->max_insert_length &&
12731324
s->lookahead >= MIN_MATCH) {
1274-
s->match_length--; /* string at strstart already in hash table */
1325+
s->match_length--; /* string at strstart already in table */
12751326
do {
12761327
s->strstart++;
12771328
INSERT_STRING(s, s->strstart, hash_head);

deflate.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515

1616
#include "zutil.h"
1717

18+
/* define NO_GZIP when compiling if you want to disable gzip header and
19+
trailer creation by deflate(). NO_GZIP would be used to avoid linking in
20+
the crc code when it is not needed. For shared libraries, gzip encoding
21+
should be left enabled. */
22+
#ifndef NO_GZIP
23+
# define GZIP
24+
#endif
25+
1826
/* ===========================================================================
1927
* Internal compression state.
2028
*/
@@ -86,7 +94,7 @@ typedef struct internal_state {
8694
ulg pending_buf_size; /* size of pending_buf */
8795
Bytef *pending_out; /* next pending byte to output to the stream */
8896
int pending; /* nb of bytes in the pending buffer */
89-
int noheader; /* suppress zlib header and adler32 */
97+
int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
9098
Byte data_type; /* UNKNOWN, BINARY or ASCII */
9199
Byte method; /* STORED (for zip only) or DEFLATED */
92100
int last_flush; /* value of flush param for previous deflate call */

gzio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ int ZEXPORTVA gzprintf (gzFile file, const char *format, /* args */ ...)
608608
va_end(va);
609609
# endif
610610
#endif
611-
if (len <= 0 || len >= sizeof(buf) || buf[sizeof(buf) - 1] != 0)
611+
if (len <= 0 || len >= (int)sizeof(buf) || buf[sizeof(buf) - 1] != 0)
612612
return 0;
613613
return gzwrite(file, buf, (unsigned)len);
614614
}

0 commit comments

Comments
 (0)