98 void makefixed
OF((
void));
110 strm->total_in = strm->total_out = state->
total = 0;
113 strm->adler = state->
wrap & 1;
117 state->
dmax = 32768U;
124 Tracev((stderr,
"inflate: reset\n"));
153 if (windowBits < 0) {
155 windowBits = -windowBits;
158 wrap = (windowBits >> 4) + 1;
166 if (windowBits && (windowBits < 8 || windowBits > 15))
175 state->
wbits = (unsigned)windowBits;
189 stream_size != (
int)(
sizeof(
z_stream)))
193 if (strm->zalloc == (alloc_func)0) {
201 if (strm->zfree == (free_func)0)
210 Tracev((stderr,
"inflate: allocated\n"));
244 value &= (1L <<
bits) - 1;
245 state->
hold += value << state->
bits;
264 static int virgin = 1;
265 static code *lenfix, *distfix;
266 static code fixed[544];
275 while (sym < 144) state->lens[sym++] = 8;
276 while (sym < 256) state->lens[sym++] = 9;
277 while (sym < 280) state->lens[sym++] = 7;
278 while (sym < 288) state->lens[sym++] = 8;
286 while (sym < 32) state->lens[sym++] = 5;
297 state->lencode = lenfix;
299 state->distcode = distfix;
330 puts(
" /* inffixed.h -- table for decoding fixed codes");
331 puts(
" * Generated automatically by makefixed().");
334 puts(
" /* WARNING: this file should *not* be used by applications.");
335 puts(
" It is part of the implementation of this library and is");
336 puts(
" subject to change. Applications should only use zlib.h.");
340 printf(
" static const code lenfix[%u] = {", size);
343 if ((low % 7) == 0) printf(
"\n ");
344 printf(
"{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op,
345 state.lencode[low].bits, state.lencode[low].val);
346 if (++low == size)
break;
351 printf(
"\n static const code distfix[%u] = {", size);
354 if ((low % 6) == 0) printf(
"\n ");
355 printf(
"{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
356 state.distcode[low].val);
357 if (++low == size)
break;
389 state->
window = (
unsigned char FAR *)
391 sizeof(
unsigned char));
396 if (state->
wsize == 0) {
403 copy = out - strm->avail_out;
404 if (copy >= state->
wsize) {
411 if (dist > copy) dist =
copy;
420 state->
wnext += dist;
432 # define UPDATE(check, buf, len) \
433 (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
435 # define UPDATE(check, buf, len) adler32(check, buf, len)
440 # define CRC2(check, word) \
442 hbuf[0] = (unsigned char)(word); \
443 hbuf[1] = (unsigned char)((word) >> 8); \
444 check = crc32(check, hbuf, 2); \
447 # define CRC4(check, word) \
449 hbuf[0] = (unsigned char)(word); \
450 hbuf[1] = (unsigned char)((word) >> 8); \
451 hbuf[2] = (unsigned char)((word) >> 16); \
452 hbuf[3] = (unsigned char)((word) >> 24); \
453 check = crc32(check, hbuf, 4); \
460 put = strm->next_out; \
461 left = strm->avail_out; \
462 next = strm->next_in; \
463 have = strm->avail_in; \
464 hold = state->hold; \
465 bits = state->bits; \
471 strm->next_out = put; \
472 strm->avail_out = left; \
473 strm->next_in = next; \
474 strm->avail_in = have; \
475 state->hold = hold; \
476 state->bits = bits; \
490 if (have == 0) goto inf_leave; \
492 hold += (unsigned long)(*next++) << bits; \
498 #define NEEDBITS(n) \
500 while (bits < (unsigned)(n)) \
506 ((unsigned)hold & ((1U << (n)) - 1))
509 #define DROPBITS(n) \
512 bits -= (unsigned)(n); \
609 unsigned char FAR *
next;
610 unsigned char FAR *put;
616 unsigned char FAR *from;
622 unsigned char hbuf[4];
624 static const unsigned short order[19] =
625 {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
628 (strm->next_in ==
Z_NULL && strm->avail_in != 0))
638 switch (state->
mode) {
640 if (state->
wrap == 0) {
646 if ((state->
wrap & 2) && hold == 0x8b1f) {
655 state->
head->done = -1;
656 if (!(state->
wrap & 1) ||
660 ((
BITS(8) << 8) + (hold >> 8)) % 31) {
661 strm->msg = (
char *)
"incorrect header check";
666 strm->msg = (
char *)
"unknown compression method";
672 if (state->
wbits == 0)
674 else if (len > state->
wbits) {
675 strm->msg = (
char *)
"invalid window size";
679 state->
dmax = 1U << len;
680 Tracev((stderr,
"inflate: zlib header ok\n"));
688 state->
flags = (int)(hold);
690 strm->msg = (
char *)
"unknown compression method";
694 if (state->
flags & 0xe000) {
695 strm->msg = (
char *)
"unknown header flags set";
700 state->
head->text = (int)((hold >> 8) & 1);
714 state->
head->xflags = (int)(hold & 0xff);
715 state->
head->os = (int)(hold >> 8);
721 if (state->
flags & 0x0400) {
723 state->
length = (unsigned)(hold);
725 state->
head->extra_len = (unsigned)hold;
733 if (state->
flags & 0x0400) {
735 if (copy > have) copy =
have;
741 len + copy > state->
head->extra_max ?
742 state->
head->extra_max - len : copy);
744 if (state->
flags & 0x0200)
750 if (state->
length)
goto inf_leave;
755 if (state->
flags & 0x0800) {
756 if (have == 0)
goto inf_leave;
759 len = (unsigned)(next[copy++]);
764 }
while (len && copy < have);
765 if (state->
flags & 0x0200)
769 if (len)
goto inf_leave;
776 if (state->
flags & 0x1000) {
777 if (have == 0)
goto inf_leave;
780 len = (unsigned)(next[copy++]);
785 }
while (len && copy < have);
786 if (state->
flags & 0x0200)
790 if (len)
goto inf_leave;
796 if (state->
flags & 0x0200) {
798 if (hold != (state->
check & 0xffff)) {
799 strm->msg = (
char *)
"header crc mismatch";
806 state->
head->hcrc = (int)((state->
flags >> 9) & 1);
807 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;
882 if (copy > have) copy =
have;
883 if (copy > left) copy = left;
884 if (copy == 0)
goto inf_leave;
893 Tracev((stderr,
"inflate: stored end\n"));
904 #ifndef PKZIP_BUG_WORKAROUND
905 if (state->
nlen > 286 || state->
ndist > 30) {
906 strm->msg = (
char *)
"too many length or distance symbols";
911 Tracev((stderr,
"inflate: table sizes ok\n"));
917 state->
lens[order[state->
have++]] = (
unsigned short)
BITS(3);
920 while (state->
have < 19)
921 state->
lens[order[state->
have++]] = 0;
928 strm->msg = (
char *)
"invalid code lengths set";
932 Tracev((stderr,
"inflate: code lengths ok\n"));
939 if ((
unsigned)(here.
bits) <= bits)
break;
947 if (here.
val == 16) {
950 if (state->
have == 0) {
951 strm->msg = (
char *)
"invalid bit length repeat";
959 else if (here.
val == 17) {
974 strm->msg = (
char *)
"invalid bit length repeat";
979 state->
lens[state->
have++] = (
unsigned short)len;
987 if (state->
lens[256] == 0) {
988 strm->msg = (
char *)
"invalid code -- missing end-of-block";
1002 strm->msg = (
char *)
"invalid literal/lengths set";
1011 strm->msg = (
char *)
"invalid distances set";
1015 Tracev((stderr,
"inflate: codes ok\n"));
1017 if (flush ==
Z_TREES)
goto inf_leave;
1021 if (have >= 6 && left >= 258) {
1032 if ((
unsigned)(here.
bits) <= bits)
break;
1035 if (here.
op && (here.
op & 0xf0) == 0) {
1040 if ((
unsigned)(last.
bits + here.
bits) <= bits)
break;
1049 if ((
int)(here.
op) == 0) {
1051 "inflate: literal '%c'\n" :
1052 "inflate: literal 0x%02x\n", here.
val));
1057 Tracevv((stderr,
"inflate: end of block\n"));
1063 strm->msg = (
char *)
"invalid literal/length code";
1067 state->
extra = (unsigned)(here.
op) & 15;
1082 if ((
unsigned)(here.
bits) <= bits)
break;
1085 if ((here.
op & 0xf0) == 0) {
1090 if ((
unsigned)(last.
bits + here.
bits) <= bits)
break;
1099 strm->msg = (
char *)
"invalid distance code";
1104 state->
extra = (
unsigned)(here.
op) & 15;
1113 #ifdef INFLATE_STRICT
1115 strm->msg = (
char *)
"invalid distance too far back";
1123 if (left == 0)
goto inf_leave;
1125 if (state->
offset > copy) {
1127 if (copy > state->
whave) {
1129 strm->msg = (
char *)
"invalid distance too far back";
1133 #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1134 Trace((stderr,
"inflate.c too far\n"));
1135 copy -= state->
whave;
1137 if (copy > left) copy = left;
1147 if (copy > state->
wnext) {
1148 copy -= state->
wnext;
1156 from = put - state->
offset;
1159 if (copy > left) copy = left;
1168 if (left == 0)
goto inf_leave;
1169 *put++ = (
unsigned char)(state->
length);
1177 strm->total_out += out;
1178 state->
total += out;
1180 strm->adler = state->
check =
1185 state->
flags ? hold :
1188 strm->msg = (
char *)
"incorrect data check";
1193 Tracev((stderr,
"inflate: check matches trailer\n"));
1200 if (hold != (state->
total & 0xffffffffUL)) {
1201 strm->msg = (
char *)
"incorrect length check";
1206 Tracev((stderr,
"inflate: length matches trailer\n"));
1231 if (state->
wsize || (out != strm->avail_out && state->
mode <
BAD &&
1237 in -= strm->avail_in;
1238 out -= strm->avail_out;
1239 strm->total_in += in;
1240 strm->total_out += out;
1241 state->
total += out;
1242 if (state->
wrap && out)
1243 strm->adler = state->
check =
1245 strm->data_type = state->
bits + (state->
last ? 64 : 0) +
1248 if (((in == 0 && out == 0) || flush ==
Z_FINISH) && ret ==
Z_OK)
1257 if (strm ==
Z_NULL || strm->state ==
Z_NULL || strm->zfree == (free_func)0)
1261 ZFREE(strm, strm->state);
1263 Tracev((stderr,
"inflate: end\n"));
1273 unsigned long dictid;
1274 unsigned char *
next;
1287 dictid =
adler32(dictid, dictionary, dictLength);
1288 if (dictid != state->
check)
1294 next = strm->next_out;
1295 avail = strm->avail_out;
1296 strm->next_out = (
Bytef *)dictionary + dictLength;
1297 strm->avail_out = 0;
1299 strm->avail_out = avail;
1300 strm->next_out =
next;
1306 Tracev((stderr,
"inflate: dictionary set\n"));
1340 unsigned char FAR *buf;
1348 while (next < len && got < 4) {
1349 if ((
int)(buf[next]) == (got < 2 ? 0 : 0xff))
1365 unsigned long in, out;
1366 unsigned char buf[4];
1380 while (state->
bits >= 8) {
1381 buf[len++] = (
unsigned char)(state->
hold);
1391 strm->avail_in -= len;
1392 strm->next_in += len;
1393 strm->total_in += len;
1397 in = strm->total_in; out = strm->total_out;
1399 strm->total_in = in; strm->total_out = out;
1428 unsigned char FAR *
window;
1433 source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
1443 window = (
unsigned char FAR *)
1444 ZALLOC(source, 1U << state->
wbits,
sizeof(
unsigned char));
1446 ZFREE(source, copy);
1454 if (state->lencode >= state->codes &&
1455 state->lencode <= state->codes +
ENOUGH - 1) {
1456 copy->lencode = copy->codes + (state->lencode - state->codes);
1457 copy->distcode = copy->codes + (state->distcode - state->codes);
1459 copy->next = copy->codes + (state->next - state->codes);
1461 wsize = 1U << state->wbits;
1462 zmemcpy(window, state->window, wsize);
1477 state->
sane = !subvert;
1478 #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1491 if (strm ==
Z_NULL || strm->state ==
Z_NULL)
return -1L << 16;
1493 return ((
long)(state->
back) << 16) +