83 #if defined( __MVS__ )
97 #pragma csect( CODE, "inflateC" )
98 #pragma csect( STATIC, "inflateS" )
99 #pragma csect( TEST, "inflateT" )
102 #if defined( INC_ALL )
124 void makefixed
OF((
void));
135 strm->total_in = strm->total_out = state->
total = 0;
141 state->
dmax = 32768U;
151 Tracev((stderr,
"inflate: reset\n"));
165 if (windowBits < 0) {
167 windowBits = -windowBits;
170 wrap = (windowBits >> 4) + 1;
178 if (windowBits && (windowBits < 8 || windowBits > 15))
187 state->
wbits = (unsigned)windowBits;
192 const char *version,
int stream_size)
198 stream_size != (
int)(
sizeof(
z_stream)))
202 if (strm->zalloc == (alloc_func)0) {
206 if (strm->zfree == (free_func)0) strm->zfree =
zcfree;
210 Tracev((stderr,
"inflate: allocated\n"));
239 value &= (1L <<
bits) - 1;
240 state->
hold += value << state->
bits;
258 static int virgin = 1;
259 static code *lenfix, *distfix;
260 static code fixed[544];
269 while (sym < 144) state->lens[sym++] = 8;
270 while (sym < 256) state->lens[sym++] = 9;
271 while (sym < 280) state->lens[sym++] = 7;
272 while (sym < 288) state->lens[sym++] = 8;
280 while (sym < 32) state->lens[sym++] = 5;
291 state->lencode = lenfix;
293 state->distcode = distfix;
324 puts(
" /* inffixed.h -- table for decoding fixed codes");
325 puts(
" * Generated automatically by makefixed().");
328 puts(
" /* WARNING: this file should *not* be used by applications.");
329 puts(
" It is part of the implementation of this library and is");
330 puts(
" subject to change. Applications should only use zlib.h.");
334 printf(
" static const code lenfix[%u] = {", size);
337 if ((low % 7) == 0) printf(
"\n ");
338 printf(
"{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
339 state.lencode[low].val);
340 if (++low == size)
break;
345 printf(
"\n static const code distfix[%u] = {", size);
348 if ((low % 6) == 0) printf(
"\n ");
349 printf(
"{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
350 state.distcode[low].val);
351 if (++low == size)
break;
381 state->
window = (
unsigned char FAR *)
383 sizeof(
unsigned char));
388 if (state->
wsize == 0) {
395 copy = out - strm->avail_out;
396 if (copy >= state->
wsize) {
403 if (dist > copy) dist = copy;
412 state->
wnext += dist;
424 # define UPDATE(check, buf, len) \
425 (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
427 # define UPDATE(check, buf, len) adler32(check, buf, len)
432 # define CRC2(check, word) \
434 hbuf[0] = (unsigned char)(word); \
435 hbuf[1] = (unsigned char)((word) >> 8); \
436 check = crc32(check, hbuf, 2); \
439 # define CRC4(check, word) \
441 hbuf[0] = (unsigned char)(word); \
442 hbuf[1] = (unsigned char)((word) >> 8); \
443 hbuf[2] = (unsigned char)((word) >> 16); \
444 hbuf[3] = (unsigned char)((word) >> 24); \
445 check = crc32(check, hbuf, 4); \
452 put = strm->next_out; \
453 left = strm->avail_out; \
454 next = strm->next_in; \
455 have = strm->avail_in; \
456 hold = state->hold; \
457 bits = state->bits; \
463 strm->next_out = put; \
464 strm->avail_out = left; \
465 strm->next_in = next; \
466 strm->avail_in = have; \
467 state->hold = hold; \
468 state->bits = bits; \
482 if (have == 0) goto inf_leave; \
484 hold += (unsigned long)(*next++) << bits; \
490 #define NEEDBITS(n) \
492 while (bits < (unsigned)(n)) \
498 ((unsigned)hold & ((1U << (n)) - 1))
501 #define DROPBITS(n) \
504 bits -= (unsigned)(n); \
516 ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
517 (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
604 unsigned char FAR *
next;
605 unsigned char FAR *put;
611 unsigned char FAR *from;
617 unsigned char hbuf[4];
619 static const unsigned short order[19] =
620 {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
623 (strm->next_in ==
Z_NULL && strm->avail_in != 0))
633 switch (state->
mode) {
635 if (state->
wrap == 0) {
641 if ((state->
wrap & 2) && hold == 0x8b1f) {
643 CRC2(state->
check, hold);
650 state->
head->done = -1;
651 if (!(state->
wrap & 1) ||
655 ((
BITS(8) << 8) + (hold >> 8)) % 31) {
656 strm->msg = (
char *)
"incorrect header check";
661 strm->msg = (
char *)
"unknown compression method";
667 if (state->
wbits == 0)
669 else if (len > state->
wbits) {
670 strm->msg = (
char *)
"invalid window size";
674 state->
dmax = 1U << len;
675 Tracev((stderr,
"inflate: zlib header ok\n"));
683 state->
flags = (int)(hold);
685 strm->msg = (
char *)
"unknown compression method";
689 if (state->
flags & 0xe000) {
690 strm->msg = (
char *)
"unknown header flags set";
695 state->
head->text = (int)((hold >> 8) & 1);
696 if (state->
flags & 0x0200) CRC2(state->
check, hold);
703 if (state->
flags & 0x0200) CRC4(state->
check, hold);
709 state->
head->xflags = (int)(hold & 0xff);
710 state->
head->os = (int)(hold >> 8);
712 if (state->
flags & 0x0200) CRC2(state->
check, hold);
716 if (state->
flags & 0x0400) {
718 state->
length = (unsigned)(hold);
720 state->
head->extra_len = (unsigned)hold;
721 if (state->
flags & 0x0200) CRC2(state->
check, hold);
728 if (state->
flags & 0x0400) {
730 if (copy > have) copy =
have;
736 len + copy > state->
head->extra_max ?
737 state->
head->extra_max - len : copy);
739 if (state->
flags & 0x0200)
740 state->
check = crc32(state->
check, next, copy);
745 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)
761 state->
check = crc32(state->
check, next, copy);
764 if (len)
goto inf_leave;
771 if (state->
flags & 0x1000) {
772 if (have == 0)
goto inf_leave;
775 len = (unsigned)(next[copy++]);
780 }
while (len && copy < have);
781 if (state->
flags & 0x0200)
782 state->
check = crc32(state->
check, next, copy);
785 if (len)
goto inf_leave;
791 if (state->
flags & 0x0200) {
793 if (hold != (state->
check & 0xffff)) {
794 strm->msg = (
char *)
"header crc mismatch";
801 state->
head->hcrc = (int)((state->
flags >> 9) & 1);
802 state->
head->done = 1;
833 Tracev((stderr,
"inflate: stored block%s\n",
834 state->
last ?
" (last)" :
""));
839 Tracev((stderr,
"inflate: fixed codes block%s\n",
840 state->
last ?
" (last)" :
""));
848 Tracev((stderr,
"inflate: dynamic codes block%s\n",
849 state->
last ?
" (last)" :
""));
853 strm->msg = (
char *)
"invalid block type";
861 if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
862 strm->msg = (
char *)
"invalid stored block lengths";
866 state->
length = (unsigned)hold & 0xffff;
867 Tracev((stderr,
"inflate: stored length %u\n",
871 if (flush ==
Z_TREES)
goto inf_leave;
877 if (copy > have) copy =
have;
878 if (copy > left) copy = left;
879 if (copy == 0)
goto inf_leave;
888 Tracev((stderr,
"inflate: stored end\n"));
899 #ifndef PKZIP_BUG_WORKAROUND
900 if (state->
nlen > 286 || state->
ndist > 30) {
901 strm->msg = (
char *)
"too many length or distance symbols";
906 Tracev((stderr,
"inflate: table sizes ok\n"));
912 state->
lens[order[state->
have++]] = (
unsigned short)
BITS(3);
915 while (state->
have < 19)
916 state->
lens[order[state->
have++]] = 0;
923 strm->msg = (
char *)
"invalid code lengths set";
927 Tracev((stderr,
"inflate: code lengths ok\n"));
934 if ((
unsigned)(here.
bits) <= bits)
break;
943 if (here.
val == 16) {
946 if (state->
have == 0) {
947 strm->msg = (
char *)
"invalid bit length repeat";
955 else if (here.
val == 17) {
970 strm->msg = (
char *)
"invalid bit length repeat";
975 state->
lens[state->
have++] = (
unsigned short)len;
983 if (state->
lens[256] == 0) {
984 strm->msg = (
char *)
"invalid code -- missing end-of-block";
998 strm->msg = (
char *)
"invalid literal/lengths set";
1007 strm->msg = (
char *)
"invalid distances set";
1011 Tracev((stderr,
"inflate: codes ok\n"));
1013 if (flush ==
Z_TREES)
goto inf_leave;
1017 if (have >= 6 && left >= 258) {
1028 if ((
unsigned)(here.
bits) <= bits)
break;
1031 if (here.
op && (here.
op & 0xf0) == 0) {
1036 if ((
unsigned)(last.
bits + here.
bits) <= bits)
break;
1045 if ((
int)(here.
op) == 0) {
1047 "inflate: literal '%c'\n" :
1048 "inflate: literal 0x%02x\n", here.
val));
1053 Tracevv((stderr,
"inflate: end of block\n"));
1059 strm->msg = (
char *)
"invalid literal/length code";
1063 state->
extra = (unsigned)(here.
op) & 15;
1078 if ((
unsigned)(here.
bits) <= bits)
break;
1081 if ((here.
op & 0xf0) == 0) {
1086 if ((
unsigned)(last.
bits + here.
bits) <= bits)
break;
1095 strm->msg = (
char *)
"invalid distance code";
1100 state->
extra = (
unsigned)(here.
op) & 15;
1109 #ifdef INFLATE_STRICT
1111 strm->msg = (
char *)
"invalid distance too far back";
1119 if (left == 0)
goto inf_leave;
1121 if (state->
offset > copy) {
1122 copy = state->
offset - copy;
1123 if (copy > state->
whave) {
1125 strm->msg = (
char *)
"invalid distance too far back";
1129 #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1130 Trace((stderr,
"inflate.c too far\n"));
1131 copy -= state->
whave;
1133 if (copy > left) copy = left;
1143 if (copy > state->
wnext) {
1144 copy -= state->
wnext;
1152 from = put - state->
offset;
1155 if (copy > left) copy = left;
1164 if (left == 0)
goto inf_leave;
1165 *put++ = (
unsigned char)(state->
length);
1173 strm->total_out += out;
1174 state->
total += out;
1176 strm->adler = state->
check =
1181 state->
flags ? hold :
1184 strm->msg = (
char *)
"incorrect data check";
1189 Tracev((stderr,
"inflate: check matches trailer\n"));
1196 if (hold != (state->
total & 0xffffffffUL)) {
1197 strm->msg = (
char *)
"incorrect length check";
1202 Tracev((stderr,
"inflate: length matches trailer\n"));
1227 if (state->
wsize || (state->
mode <
CHECK && out != strm->avail_out))
1232 in -= strm->avail_in;
1233 out -= strm->avail_out;
1234 strm->total_in += in;
1235 strm->total_out += out;
1236 state->
total += out;
1237 if (state->
wrap && out)
1238 strm->adler = state->
check =
1240 strm->data_type = state->
bits + (state->
last ? 64 : 0) +
1243 if (((in == 0 && out == 0) || flush ==
Z_FINISH) && ret ==
Z_OK)
1251 if (strm ==
Z_NULL || strm->state ==
Z_NULL || strm->zfree == (free_func)0)
1255 ZFREE(strm, strm->state);
1257 Tracev((stderr,
"inflate: end\n"));
1276 id =
adler32(
id, dictionary, dictLength);
1277 if (
id != state->
check)
1286 if (dictLength > state->
wsize) {
1294 state->
whave = dictLength;
1297 Tracev((stderr,
"inflate: dictionary set\n"));
1335 while (next < len && got < 4) {
1336 if ((
int)(buf[next]) == (got < 2 ? 0 : 0xff))
1351 unsigned long in, out;
1352 unsigned char buf[4];
1366 while (state->
bits >= 8) {
1367 buf[len++] = (
unsigned char)(state->
hold);
1377 strm->avail_in -= len;
1378 strm->next_in += len;
1379 strm->total_in += len;
1383 in = strm->total_in; out = strm->total_out;
1385 strm->total_in = in; strm->total_out = out;
1411 unsigned char FAR *
window;
1416 source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
1426 window = (
unsigned char FAR *)
1427 ZALLOC(source, 1U << state->
wbits,
sizeof(
unsigned char));
1429 ZFREE(source, copy);
1444 wsize = 1U << state->
wbits;
1458 state->
sane = !subvert;
1459 #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1471 if (strm ==
Z_NULL || strm->state ==
Z_NULL)
return -1L << 16;
1473 return ((
long)(state->
back) << 16) +