119 state->
dmax = 32768U;
126 Tracev((stderr,
"inflate: reset\n"));
150 if (windowBits < 0) {
151 if (windowBits < -15)
154 windowBits = -windowBits;
157 wrap = (windowBits >> 4) + 5;
165 if (windowBits && (windowBits < 8 || windowBits > 15))
174 state->
wbits = (unsigned)windowBits;
179 const char *version,
int stream_size) {
184 stream_size != (
int)(
sizeof(
z_stream)))
193 strm->opaque = (voidpf)0;
205 Tracev((stderr,
"inflate: allocated\n"));
236 value &= (1L <<
bits) - 1;
237 state->
hold += (unsigned)value << state->
bits;
254 static int virgin = 1;
255 static code *lenfix, *distfix;
256 static code fixed[544];
265 while (sym < 144) state->lens[sym++] = 8;
266 while (sym < 256) state->lens[sym++] = 9;
267 while (sym < 280) state->lens[sym++] = 7;
268 while (sym < 288) state->lens[sym++] = 8;
276 while (sym < 32) state->lens[sym++] = 5;
287 state->lencode = lenfix;
289 state->distcode = distfix;
320 puts(
" /* inffixed.h -- table for decoding fixed codes");
321 puts(
" * Generated automatically by makefixed().");
324 puts(
" /* WARNING: this file should *not* be used by applications.");
325 puts(
" It is part of the implementation of this library and is");
326 puts(
" subject to change. Applications should only use zlib.h.");
330 printf(
" static const code lenfix[%u] = {", size);
333 if ((low % 7) == 0) printf(
"\n ");
334 printf(
"{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op,
335 state.lencode[low].bits, state.lencode[low].val);
336 if (++low == size)
break;
341 printf(
"\n static const code distfix[%u] = {", size);
344 if ((low % 6) == 0) printf(
"\n ");
345 printf(
"{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
346 state.distcode[low].val);
347 if (++low == size)
break;
376 state->
window = (
unsigned char FAR *)
378 sizeof(
unsigned char));
383 if (state->
wsize == 0) {
390 if (copy >= state->
wsize) {
397 if (dist > copy) dist = copy;
406 state->
wnext += dist;
418# define UPDATE_CHECK(check, buf, len) \
419 (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
421# define UPDATE_CHECK(check, buf, len) adler32(check, buf, len)
426# define CRC2(check, word) \
428 hbuf[0] = (unsigned char)(word); \
429 hbuf[1] = (unsigned char)((word) >> 8); \
430 check = crc32(check, hbuf, 2); \
433# define CRC4(check, word) \
435 hbuf[0] = (unsigned char)(word); \
436 hbuf[1] = (unsigned char)((word) >> 8); \
437 hbuf[2] = (unsigned char)((word) >> 16); \
438 hbuf[3] = (unsigned char)((word) >> 24); \
439 check = crc32(check, hbuf, 4); \
446 put = strm->next_out; \
447 left = strm->avail_out; \
448 next = strm->next_in; \
449 have = strm->avail_in; \
450 hold = state->hold; \
451 bits = state->bits; \
457 strm->next_out = put; \
458 strm->avail_out = left; \
459 strm->next_in = next; \
460 strm->avail_in = have; \
461 state->hold = hold; \
462 state->bits = bits; \
476 if (have == 0) goto inf_leave; \
478 hold += (unsigned long)(*next++) << bits; \
486 while (bits < (unsigned)(n)) \
492 ((unsigned)hold & ((1U << (n)) - 1))
498 bits -= (unsigned)(n); \
592 z_const
unsigned char FAR *
next;
593 unsigned char FAR *put;
599 unsigned char FAR *from;
605 unsigned char hbuf[4];
607 static const unsigned short order[19] =
608 {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
621 switch (state->
mode) {
623 if (state->
wrap == 0) {
629 if ((state->
wrap & 2) &&
hold == 0x8b1f) {
630 if (state->
wbits == 0)
639 state->
head->done = -1;
640 if (!(state->
wrap & 1) ||
644 ((
BITS(8) << 8) + (
hold >> 8)) % 31) {
645 strm->msg = (
char *)
"incorrect header check";
650 strm->msg = (
char *)
"unknown compression method";
656 if (state->
wbits == 0)
658 if (len > 15 || len > state->
wbits) {
659 strm->msg = (
char *)
"invalid window size";
663 state->
dmax = 1U << len;
665 Tracev((stderr,
"inflate: zlib header ok\n"));
675 strm->msg = (
char *)
"unknown compression method";
679 if (state->
flags & 0xe000) {
680 strm->msg = (
char *)
"unknown header flags set";
685 state->
head->text = (int)((
hold >> 8) & 1);
686 if ((state->
flags & 0x0200) && (state->
wrap & 4))
695 if ((state->
flags & 0x0200) && (state->
wrap & 4))
703 state->
head->xflags = (int)(
hold & 0xff);
706 if ((state->
flags & 0x0200) && (state->
wrap & 4))
712 if (state->
flags & 0x0400) {
716 state->
head->extra_len = (unsigned)
hold;
717 if ((state->
flags & 0x0200) && (state->
wrap & 4))
726 if (state->
flags & 0x0400) {
732 (len = state->
head->extra_len - state->
length) <
733 state->
head->extra_max) {
735 len + copy > state->
head->extra_max ?
736 state->
head->extra_max - len : copy);
738 if ((state->
flags & 0x0200) && (state->
wrap & 4))
744 if (state->
length)
goto inf_leave;
750 if (state->
flags & 0x0800) {
751 if (
have == 0)
goto inf_leave;
754 len = (unsigned)(
next[copy++]);
758 state->
head->name[state->
length++] = (Bytef)len;
759 }
while (len && copy <
have);
760 if ((state->
flags & 0x0200) && (state->
wrap & 4))
764 if (len)
goto inf_leave;
772 if (state->
flags & 0x1000) {
773 if (
have == 0)
goto inf_leave;
776 len = (unsigned)(
next[copy++]);
780 state->
head->comment[state->
length++] = (Bytef)len;
781 }
while (len && copy <
have);
782 if ((state->
flags & 0x0200) && (state->
wrap & 4))
786 if (len)
goto inf_leave;
793 if (state->
flags & 0x0200) {
796 strm->msg = (
char *)
"header crc mismatch";
803 state->
head->hcrc = (int)((state->
flags >> 9) & 1);
804 state->
head->done = 1;
838 Tracev((stderr,
"inflate: stored block%s\n",
839 state->
last ?
" (last)" :
""));
844 Tracev((stderr,
"inflate: fixed codes block%s\n",
845 state->
last ?
" (last)" :
""));
853 Tracev((stderr,
"inflate: dynamic codes block%s\n",
854 state->
last ?
" (last)" :
""));
858 strm->msg = (
char *)
"invalid block type";
866 if ((
hold & 0xffff) != ((
hold >> 16) ^ 0xffff)) {
867 strm->msg = (
char *)
"invalid stored block lengths";
872 Tracev((stderr,
"inflate: stored length %u\n",
876 if (flush ==
Z_TREES)
goto inf_leave;
885 if (copy > left) copy = left;
886 if (copy == 0)
goto inf_leave;
895 Tracev((stderr,
"inflate: stored end\n"));
906#ifndef PKZIP_BUG_WORKAROUND
907 if (state->
nlen > 286 || state->
ndist > 30) {
908 strm->msg = (
char *)
"too many length or distance symbols";
913 Tracev((stderr,
"inflate: table sizes ok\n"));
920 state->
lens[order[state->
have++]] = (
unsigned short)
BITS(3);
923 while (state->
have < 19)
924 state->
lens[order[state->
have++]] = 0;
931 strm->msg = (
char *)
"invalid code lengths set";
935 Tracev((stderr,
"inflate: code lengths ok\n"));
943 if ((
unsigned)(here.
bits) <=
bits)
break;
951 if (here.
val == 16) {
954 if (state->
have == 0) {
955 strm->msg = (
char *)
"invalid bit length repeat";
963 else if (here.
val == 17) {
978 strm->msg = (
char *)
"invalid bit length repeat";
983 state->
lens[state->
have++] = (
unsigned short)len;
991 if (state->
lens[256] == 0) {
992 strm->msg = (
char *)
"invalid code -- missing end-of-block";
1006 strm->msg = (
char *)
"invalid literal/lengths set";
1015 strm->msg = (
char *)
"invalid distances set";
1019 Tracev((stderr,
"inflate: codes ok\n"));
1021 if (flush ==
Z_TREES)
goto inf_leave;
1027 if (
have >= 6 && left >= 258) {
1038 if ((
unsigned)(here.
bits) <=
bits)
break;
1041 if (here.
op && (here.
op & 0xf0) == 0) {
1055 if ((
int)(here.
op) == 0) {
1057 "inflate: literal '%c'\n" :
1058 "inflate: literal 0x%02x\n", here.
val));
1063 Tracevv((stderr,
"inflate: end of block\n"));
1069 strm->msg = (
char *)
"invalid literal/length code";
1073 state->
extra = (unsigned)(here.
op) & 15;
1090 if ((
unsigned)(here.
bits) <=
bits)
break;
1093 if ((here.
op & 0xf0) == 0) {
1107 strm->msg = (
char *)
"invalid distance code";
1112 state->
extra = (unsigned)(here.
op) & 15;
1122#ifdef INFLATE_STRICT
1124 strm->msg = (
char *)
"invalid distance too far back";
1133 if (left == 0)
goto inf_leave;
1135 if (state->
offset > copy) {
1136 copy = state->
offset - copy;
1137 if (copy > state->
whave) {
1139 strm->msg = (
char *)
"invalid distance too far back";
1143#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1144 Trace((stderr,
"inflate.c too far\n"));
1145 copy -= state->
whave;
1147 if (copy > left) copy = left;
1157 if (copy > state->
wnext) {
1158 copy -= state->
wnext;
1166 from = put - state->
offset;
1169 if (copy > left) copy = left;
1178 if (left == 0)
goto inf_leave;
1179 *put++ = (
unsigned char)(state->
length);
1187 strm->total_out += out;
1188 state->
total += out;
1189 if ((state->
wrap & 4) && out)
1193 if ((state->
wrap & 4) && (
1198 strm->msg = (
char *)
"incorrect data check";
1203 Tracev((stderr,
"inflate: check matches trailer\n"));
1211 if ((state->
wrap & 4) &&
hold != (state->
total & 0xffffffff)) {
1212 strm->msg = (
char *)
"incorrect length check";
1217 Tracev((stderr,
"inflate: length matches trailer\n"));
1250 in -=
strm->avail_in;
1251 out -=
strm->avail_out;
1252 strm->total_in += in;
1253 strm->total_out += out;
1254 state->
total += out;
1255 if ((state->
wrap & 4) && out)
1258 strm->data_type = (int)state->
bits + (state->
last ? 64 : 0) +
1261 if (((in == 0 && out == 0) || flush ==
Z_FINISH) && ret ==
Z_OK)
1274 Tracev((stderr,
"inflate: end\n"));
1293 if (dictLength !=
Z_NULL)
1294 *dictLength = state->
whave;
1301 unsigned long dictid;
1313 dictid =
adler32(dictid, dictionary, dictLength);
1314 if (dictid != state->
check)
1326 Tracev((stderr,
"inflate: dictionary set\n"));
1362 while (
next < len && got < 4) {
1363 if ((
int)(buf[
next]) == (got < 2 ? 0 : 0xff))
1378 unsigned long in, out;
1379 unsigned char buf[4];
1393 while (state->
bits >= 8) {
1394 buf[len++] = (
unsigned char)(state->
hold);
1404 strm->avail_in -= len;
1405 strm->next_in += len;
1406 strm->total_in += len;
1410 if (state->
flags == -1)
1415 in =
strm->total_in; out =
strm->total_out;
1417 strm->total_in = in;
strm->total_out = out;
1442 unsigned char FAR *
window;
1456 window = (
unsigned char FAR *)
1457 ZALLOC(source, 1U << state->
wbits,
sizeof(
unsigned char));
1459 ZFREE(source, copy);
1470 copy->lencode = copy->codes + (state->
lencode - state->
codes);
1471 copy->distcode = copy->codes + (state->
distcode - state->
codes);
1473 copy->next = copy->codes + (state->
next - state->
codes);
1488#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1489 state->
sane = !subvert;
1516 return (
long)(((
unsigned long)((long)state->
back)) << 16) +
1525 return (
unsigned long)(state->
next - state->
codes);
void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start)
unsigned long ZEXPORT inflateCodesUsed(z_streamp strm)
int ZEXPORT inflateSetDictionary(z_streamp strm, const Bytef *dictionary, uInt dictLength)
long ZEXPORT inflateMark(z_streamp strm)
int ZEXPORT inflateGetDictionary(z_streamp strm, Bytef *dictionary, uInt *dictLength)
local int inflateStateCheck(z_streamp strm)
local void fixedtables(struct inflate_state FAR *state)
int ZEXPORT inflateSyncPoint(z_streamp strm)
local unsigned syncsearch(unsigned FAR *have, const unsigned char FAR *buf, unsigned len)
int ZEXPORT inflatePrime(z_streamp strm, int bits, int value)
int ZEXPORT inflateGetHeader(z_streamp strm, gz_headerp head)
int ZEXPORT inflateUndermine(z_streamp strm, int subvert)
int ZEXPORT inflateSync(z_streamp strm)
int ZEXPORT inflateResetKeep(z_streamp strm)
int ZEXPORT inflate(z_streamp strm, int flush)
int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
local int updatewindow(z_streamp strm, const Bytef *end, unsigned copy)
int ZEXPORT inflateReset(z_streamp strm)
int ZEXPORT inflateInit_(z_streamp strm, const char *version, int stream_size)
int ZEXPORT inflateEnd(z_streamp strm)
int ZEXPORT inflateCopy(z_streamp dest, z_streamp source)
#define UPDATE_CHECK(check, buf, len)
int ZEXPORT inflateValidate(z_streamp strm, int check)
int ZEXPORT inflateReset2(z_streamp strm, int windowBits)
int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, unsigned codes, code FAR *FAR *table, unsigned FAR *bits, unsigned short FAR *work)
code const FAR * distcode
unsigned char FAR * window
void(* free_func)(voidpf opaque, voidpf address)
ZEXTERN uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
gz_header FAR * gz_headerp
voidpf(* alloc_func)(voidpf opaque, uInt items, uInt size)
ZEXTERN uLong ZEXPORT crc32(uLong crc, const Bytef *buf, uInt len)
struct z_stream_s z_stream
void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr)
#define ZALLOC(strm, items, size)
voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size)
#define ZFREE(strm, addr)
void ZLIB_INTERNAL zmemcpy(Bytef *dest, const Bytef *source, uInt len)