100 void makefixed
OF((
void));
110 strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0)
126 strm->total_in = strm->total_out = state->
total = 0;
129 strm->adler = state->
wrap & 1;
133 state->
dmax = 32768U;
140 Tracev((stderr,
"inflate: reset\n"));
169 if (windowBits < 0) {
171 windowBits = -windowBits;
174 wrap = (windowBits >> 4) + 5;
182 if (windowBits && (windowBits < 8 || windowBits > 15))
191 state->
wbits = (unsigned)windowBits;
205 stream_size != (
int)(
sizeof(
z_stream)))
209 if (strm->zalloc == (alloc_func)0) {
214 strm->opaque = (voidpf)0;
217 if (strm->zfree == (free_func)0)
226 Tracev((stderr,
"inflate: allocated\n"));
262 value &= (1
L <<
bits) - 1;
263 state->
hold += (unsigned)value << state->
bits;
282 static int virgin = 1;
284 static code fixed[544];
293 while (sym < 144) state->lens[sym++] = 8;
294 while (sym < 256) state->lens[sym++] = 9;
295 while (sym < 280) state->lens[sym++] = 7;
296 while (sym < 288) state->lens[sym++] = 8;
304 while (sym < 32) state->lens[sym++] = 5;
348 puts(
" /* inffixed.h -- table for decoding fixed codes");
349 puts(
" * Generated automatically by makefixed().");
352 puts(
" /* WARNING: this file should *not* be used by applications.");
353 puts(
" It is part of the implementation of this library and is");
354 puts(
" subject to change. Applications should only use zlib.h.");
358 printf(
" static const code lenfix[%u] = {", size);
361 if ((low % 7) == 0)
printf(
"\n ");
362 printf(
"{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op,
363 state.lencode[low].bits, state.lencode[low].val);
364 if (++low == size)
break;
369 printf(
"\n static const code distfix[%u] = {", size);
372 if ((low % 6) == 0)
printf(
"\n ");
373 printf(
"{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
374 state.distcode[low].val);
375 if (++low == size)
break;
408 state->
window = (
unsigned char FAR *)
410 sizeof(
unsigned char));
415 if (state->
wsize == 0) {
422 if (copy >= state->
wsize) {
429 if (dist > copy) dist =
copy;
438 state->
wnext += dist;
450 # define UPDATE(check, buf, len) \
451 (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
453 # define UPDATE(check, buf, len) adler32(check, buf, len)
458 # define CRC2(check, word) \
460 hbuf[0] = (unsigned char)(word); \
461 hbuf[1] = (unsigned char)((word) >> 8); \
462 check = crc32(check, hbuf, 2); \
465 # define CRC4(check, word) \
467 hbuf[0] = (unsigned char)(word); \
468 hbuf[1] = (unsigned char)((word) >> 8); \
469 hbuf[2] = (unsigned char)((word) >> 16); \
470 hbuf[3] = (unsigned char)((word) >> 24); \
471 check = crc32(check, hbuf, 4); \
478 put = strm->next_out; \
479 left = strm->avail_out; \
480 next = strm->next_in; \
481 have = strm->avail_in; \
482 hold = state->hold; \
483 bits = state->bits; \
489 strm->next_out = put; \
490 strm->avail_out = left; \
491 strm->next_in = next; \
492 strm->avail_in = have; \
493 state->hold = hold; \
494 state->bits = bits; \
508 if (have == 0) goto inf_leave; \
510 hold += (unsigned long)(*next++) << bits; \
516 #define NEEDBITS(n) \
518 while (bits < (unsigned)(n)) \
524 ((unsigned)hold & ((1U << (n)) - 1))
527 #define DROPBITS(n) \
530 bits -= (unsigned)(n); \
627 z_const
unsigned char FAR *
next;
628 unsigned char FAR *put;
634 unsigned char FAR *from;
640 unsigned char hbuf[4];
642 static const unsigned short order[19] =
643 {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
646 (strm->next_in ==
Z_NULL && strm->avail_in != 0))
656 switch (state->
mode) {
658 if (state->
wrap == 0) {
664 if ((state->
wrap & 2) && hold == 0x8b1f) {
665 if (state->
wbits == 0)
668 CRC2(state->
check, hold);
675 state->
head->done = -1;
676 if (!(state->
wrap & 1) ||
680 ((
BITS(8) << 8) + (hold >> 8)) % 31) {
681 strm->msg = (
char *)
"incorrect header check";
686 strm->msg = (
char *)
"unknown compression method";
692 if (state->
wbits == 0)
694 if (len > 15 || len > state->
wbits) {
695 strm->msg = (
char *)
"invalid window size";
700 Tracev((stderr,
"inflate: zlib header ok\n"));
710 strm->msg = (
char *)
"unknown compression method";
714 if (state->
flags & 0xe000) {
715 strm->msg = (
char *)
"unknown header flags set";
720 state->
head->text = (
int)((hold >> 8) & 1);
721 if ((state->
flags & 0x0200) && (state->
wrap & 4))
722 CRC2(state->
check, hold);
729 if ((state->
flags & 0x0200) && (state->
wrap & 4))
730 CRC4(state->
check, hold);
736 state->
head->xflags = (
int)(hold & 0xff);
737 state->
head->os = (
int)(hold >> 8);
739 if ((state->
flags & 0x0200) && (state->
wrap & 4))
740 CRC2(state->
check, hold);
744 if (state->
flags & 0x0400) {
746 state->
length = (unsigned)(hold);
748 state->
head->extra_len = (unsigned)hold;
749 if ((state->
flags & 0x0200) && (state->
wrap & 4))
750 CRC2(state->
check, hold);
757 if (state->
flags & 0x0400) {
759 if (copy > have) copy =
have;
765 len + copy > state->
head->extra_max ?
766 state->
head->extra_max - len : copy);
768 if ((state->
flags & 0x0200) && (state->
wrap & 4))
774 if (state->
length)
goto inf_leave;
779 if (state->
flags & 0x0800) {
780 if (have == 0)
goto inf_leave;
783 len = (unsigned)(next[copy++]);
787 state->
head->name[state->
length++] = (Bytef)len;
788 }
while (len && copy < have);
789 if ((state->
flags & 0x0200) && (state->
wrap & 4))
793 if (len)
goto inf_leave;
800 if (state->
flags & 0x1000) {
801 if (have == 0)
goto inf_leave;
804 len = (unsigned)(next[copy++]);
808 state->
head->comment[state->
length++] = (Bytef)len;
809 }
while (len && copy < have);
810 if ((state->
flags & 0x0200) && (state->
wrap & 4))
814 if (len)
goto inf_leave;
820 if (state->
flags & 0x0200) {
822 if ((state->
wrap & 4) && hold != (state->
check & 0xffff)) {
823 strm->msg = (
char *)
"header crc mismatch";
831 state->
head->done = 1;
862 Tracev((stderr,
"inflate: stored block%s\n",
863 state->
last ?
" (last)" :
""));
868 Tracev((stderr,
"inflate: fixed codes block%s\n",
869 state->
last ?
" (last)" :
""));
877 Tracev((stderr,
"inflate: dynamic codes block%s\n",
878 state->
last ?
" (last)" :
""));
882 strm->msg = (
char *)
"invalid block type";
890 if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
891 strm->msg = (
char *)
"invalid stored block lengths";
895 state->
length = (unsigned)hold & 0xffff;
896 Tracev((stderr,
"inflate: stored length %u\n",
900 if (flush ==
Z_TREES)
goto inf_leave;
906 if (copy > have) copy =
have;
907 if (copy > left) copy =
left;
908 if (copy == 0)
goto inf_leave;
917 Tracev((stderr,
"inflate: stored end\n"));
928 #ifndef PKZIP_BUG_WORKAROUND
929 if (state->
nlen > 286 || state->
ndist > 30) {
930 strm->msg = (
char *)
"too many length or distance symbols";
935 Tracev((stderr,
"inflate: table sizes ok\n"));
941 state->
lens[order[state->
have++]] = (
unsigned short)
BITS(3);
944 while (state->
have < 19)
945 state->
lens[order[state->
have++]] = 0;
952 strm->msg = (
char *)
"invalid code lengths set";
956 Tracev((stderr,
"inflate: code lengths ok\n"));
963 if ((
unsigned)(here.
bits) <= bits)
break;
971 if (here.
val == 16) {
974 if (state->
have == 0) {
975 strm->msg = (
char *)
"invalid bit length repeat";
983 else if (here.
val == 17) {
998 strm->msg = (
char *)
"invalid bit length repeat";
1003 state->
lens[state->
have++] = (
unsigned short)len;
1008 if (state->
mode ==
BAD)
break;
1011 if (state->
lens[256] == 0) {
1012 strm->msg = (
char *)
"invalid code -- missing end-of-block";
1026 strm->msg = (
char *)
"invalid literal/lengths set";
1035 strm->msg = (
char *)
"invalid distances set";
1039 Tracev((stderr,
"inflate: codes ok\n"));
1041 if (flush ==
Z_TREES)
goto inf_leave;
1045 if (have >= 6 && left >= 258) {
1056 if ((
unsigned)(here.
bits) <= bits)
break;
1059 if (here.
op && (here.
op & 0xf0) == 0) {
1064 if ((
unsigned)(last.
bits + here.
bits) <= bits)
break;
1073 if ((
int)(here.
op) == 0) {
1075 "inflate: literal '%c'\n" :
1076 "inflate: literal 0x%02x\n", here.
val));
1081 Tracevv((stderr,
"inflate: end of block\n"));
1087 strm->msg = (
char *)
"invalid literal/length code";
1091 state->
extra = (unsigned)(here.
op) & 15;
1106 if ((
unsigned)(here.
bits) <= bits)
break;
1109 if ((here.
op & 0xf0) == 0) {
1114 if ((
unsigned)(last.
bits + here.
bits) <= bits)
break;
1123 strm->msg = (
char *)
"invalid distance code";
1128 state->
extra = (
unsigned)(here.
op) & 15;
1137 #ifdef INFLATE_STRICT
1139 strm->msg = (
char *)
"invalid distance too far back";
1147 if (left == 0)
goto inf_leave;
1149 if (state->
offset > copy) {
1151 if (copy > state->
whave) {
1153 strm->msg = (
char *)
"invalid distance too far back";
1157 #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1158 Trace((stderr,
"inflate.c too far\n"));
1159 copy -= state->
whave;
1161 if (copy > left) copy =
left;
1171 if (copy > state->
wnext) {
1172 copy -= state->
wnext;
1180 from = put - state->
offset;
1183 if (copy > left) copy =
left;
1192 if (left == 0)
goto inf_leave;
1193 *put++ = (
unsigned char)(state->
length);
1201 strm->total_out += out;
1202 state->
total += out;
1203 if ((state->
wrap & 4) && out)
1204 strm->adler = state->
check =
1207 if ((state->
wrap & 4) && (
1209 state->
flags ? hold :
1212 strm->msg = (
char *)
"incorrect data check";
1217 Tracev((stderr,
"inflate: check matches trailer\n"));
1224 if (hold != (state->
total & 0xffffffffUL)) {
1225 strm->msg = (
char *)
"incorrect length check";
1230 Tracev((stderr,
"inflate: length matches trailer\n"));
1255 if (state->
wsize || (out != strm->avail_out && state->
mode <
BAD &&
1257 if (
updatewindow(strm, strm->next_out, out - strm->avail_out)) {
1261 in -= strm->avail_in;
1262 out -= strm->avail_out;
1263 strm->total_in +=
in;
1264 strm->total_out += out;
1265 state->
total += out;
1266 if ((state->
wrap & 4) && out)
1267 strm->adler = state->
check =
1269 strm->data_type = (
int)state->
bits + (state->
last ? 64 : 0) +
1272 if (((in == 0 && out == 0) || flush ==
Z_FINISH) && ret ==
Z_OK)
1285 ZFREE(strm, strm->state);
1287 Tracev((stderr,
"inflate: end\n"));
1309 if (dictLength !=
Z_NULL)
1310 *dictLength = state->
whave;
1316 const Bytef *dictionary;
1320 unsigned long dictid;
1332 dictid =
adler32(dictid, dictionary, dictLength);
1333 if (dictid != state->
check)
1339 ret =
updatewindow(strm, dictionary + dictLength, dictLength);
1345 Tracev((stderr,
"inflate: dictionary set\n"));
1379 const
unsigned char FAR *buf;
1387 while (next < len && got < 4) {
1388 if ((
int)(buf[next]) == (got < 2 ? 0 : 0xff))
1404 unsigned long in, out;
1405 unsigned char buf[4];
1419 while (state->
bits >= 8) {
1420 buf[len++] = (
unsigned char)(state->
hold);
1430 strm->avail_in -=
len;
1431 strm->next_in +=
len;
1432 strm->total_in +=
len;
1436 in = strm->total_in; out = strm->total_out;
1438 strm->total_in =
in; strm->total_out = out;
1467 unsigned char FAR *
window;
1481 window = (
unsigned char FAR *)
1482 ZALLOC(source, 1U << state->
wbits,
sizeof(
unsigned char));
1484 ZFREE(source, copy);
1493 if (state->lencode >= state->codes &&
1494 state->lencode <= state->codes +
ENOUGH - 1) {
1495 copy->lencode = copy->codes + (state->lencode - state->codes);
1496 copy->distcode = copy->codes + (state->distcode - state->codes);
1498 copy->next = copy->codes + (state->next - state->codes);
1500 wsize = 1U << state->wbits;
1501 zmemcpy(window, state->window, wsize);
1516 #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1517 state->
sane = !subvert;
1549 return (
long)(((
unsigned long)((
long)state->
back)) << 16) +