111 strm->total_in = strm->total_out = state->
total = 0;
114 strm->adler = state->
wrap & 1;
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)))
205 Tracev((stderr,
"inflate: allocated\n"));
236 value &= (1L <<
bits) - 1;
237 state->
hold += (unsigned)value << state->
bits;
254 static int virgin = 1;
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;
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; \
484 #define NEEDBITS(n) \
486 while (bits < (unsigned)(n)) \
492 ((unsigned)hold & ((1U << (n)) - 1))
495 #define DROPBITS(n) \
498 bits -= (unsigned)(n); \
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};
611 (strm->next_in ==
Z_NULL && strm->avail_in != 0))
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);
704 state->
head->os = (
int)(hold >> 8);
706 if ((state->
flags & 0x0200) && (state->
wrap & 4))
712 if (state->
flags & 0x0400) {
714 state->
length = (unsigned)(hold);
716 state->
head->extra_len = (unsigned)hold;
717 if ((state->
flags & 0x0200) && (state->
wrap & 4))
726 if (state->
flags & 0x0400) {
728 if (copy > have) copy =
have;
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++]);
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++]);
781 }
while (len && copy < have);
782 if ((state->
flags & 0x0200) && (state->
wrap & 4))
786 if (len)
goto inf_leave;
793 if (state->
flags & 0x0200) {
795 if ((state->
wrap & 4) && hold != (state->
check & 0xffff)) {
796 strm->msg = (
char *)
"header crc mismatch";
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";
871 state->
length = (unsigned)hold & 0xffff;
872 Tracev((stderr,
"inflate: stored length %u\n",
876 if (flush ==
Z_TREES)
goto inf_leave;
884 if (copy > have) copy =
have;
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) {
1046 if ((
unsigned)(last.
bits + here.
bits) <= bits)
break;
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) {
1098 if ((
unsigned)(last.
bits + here.
bits) <= bits)
break;
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)
1190 strm->adler = state->
check =
1193 if ((state->
wrap & 4) && (
1195 state->
flags ? hold :
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"));
1244 if (state->
wsize || (out != strm->avail_out && state->
mode <
BAD &&
1246 if (
updatewindow(strm, strm->next_out, out - strm->avail_out)) {
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)
1256 strm->adler = state->
check =
1258 strm->data_type = (
int)state->
bits + (state->
last ? 64 : 0) +
1261 if (((in == 0 && out == 0) || flush ==
Z_FINISH) && ret ==
Z_OK)
1272 ZFREE(strm, strm->state);
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)
1320 ret =
updatewindow(strm, dictionary + dictLength, dictLength);
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)
1414 flags = state->
flags;
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);
1468 if (state->lencode >= state->codes &&
1469 state->lencode <= state->codes +
ENOUGH - 1) {
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);
1475 wsize = 1U << state->wbits;
1476 zmemcpy(window, state->window, wsize);
1488 #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1489 state->
sane = !subvert;
1503 if (check && state->
wrap)
1516 return (
long)(((
unsigned long)((
long)state->
back)) << 16) +
1525 return (
unsigned long)(state->
next - state->
codes);
local int inflateStateCheck(z_streamp strm)
int ZEXPORT inflateReset(z_streamp strm)
local void fixedtables(struct inflate_state FAR *state)
int ZEXPORT inflateValidate(z_streamp strm, int check)
int ZEXPORT inflateResetKeep(z_streamp strm)
code const FAR * distcode
voidpf(* alloc_func)(voidpf opaque, uInt items, uInt size)
int ZEXPORT inflateInit_(z_streamp strm, const char *version, int stream_size)
static const code lenfix[512]
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
gz_header FAR * gz_headerp
#define UPDATE_CHECK(check, buf, len)
local unsigned syncsearch(unsigned FAR *have, const unsigned char FAR *buf, unsigned len)
int ZEXPORT inflateReset2(z_streamp strm, int windowBits)
int ZEXPORT inflateSetDictionary(z_streamp strm, const Bytef *dictionary, uInt dictLength)
int ZEXPORT inflateSyncPoint(z_streamp strm)
#define ZALLOC(strm, items, size)
void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start)
#define CRC2(check, word)
int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, unsigned codes, code FAR *FAR *table, unsigned FAR *bits, unsigned short FAR *work)
static const code distfix[32]
unsigned long ZEXPORT inflateCodesUsed(z_streamp strm)
#define ZFREE(strm, addr)
typedef long(ZCALLBACK *tell_file_func) OF((voidpf opaque
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
int ZEXPORT inflateSync(z_streamp strm)
void ZLIB_INTERNAL zmemcpy(Bytef *dest, const Bytef *source, uInt len)
int ZEXPORT inflateUndermine(z_streamp strm, int subvert)
int ZEXPORT inflateGetHeader(z_streamp strm, gz_headerp head)
int ZEXPORT inflateGetDictionary(z_streamp strm, Bytef *dictionary, uInt *dictLength)
uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
int ZEXPORT inflatePrime(z_streamp strm, int bits, int value)
long ZEXPORT inflateMark(z_streamp strm)
unsigned char FAR * window
int ZEXPORT inflate(z_streamp strm, int flush)
#define CRC4(check, word)
int ZEXPORT inflateCopy(z_streamp dest, z_streamp source)
local int updatewindow(z_streamp strm, const Bytef *end, unsigned copy)
void(* free_func)(voidpf opaque, voidpf address)
voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size)
int ZEXPORT inflateEnd(z_streamp strm)
void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr)