611 unsigned char FAR *put;
617 unsigned char FAR *from;
623 unsigned char hbuf[4];
625 static const unsigned short order[19] =
626 {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
629 (strm->next_in ==
Z_NULL && strm->avail_in != 0))
639 switch (state->
mode) {
641 if (state->
wrap == 0) {
647 if ((state->
wrap & 2) && hold == 0x8b1f) {
656 state->
head->done = -1;
657 if (!(state->
wrap & 1) ||
661 ((
BITS(8) << 8) + (hold >> 8)) % 31) {
662 strm->msg = (
char *)
"incorrect header check";
667 strm->msg = (
char *)
"unknown compression method";
673 if (state->
wbits == 0)
675 else if (len > state->
wbits) {
676 strm->msg = (
char *)
"invalid window size";
680 state->
dmax = 1U << len;
681 Tracev((stderr,
"inflate: zlib header ok\n"));
689 state->
flags = (int)(hold);
691 strm->msg = (
char *)
"unknown compression method";
695 if (state->
flags & 0xe000) {
696 strm->msg = (
char *)
"unknown header flags set";
701 state->
head->text = (int)((hold >> 8) & 1);
715 state->
head->xflags = (int)(hold & 0xff);
716 state->
head->os = (int)(hold >> 8);
722 if (state->
flags & 0x0400) {
724 state->
length = (unsigned)(hold);
726 state->
head->extra_len = (unsigned)hold;
734 if (state->
flags & 0x0400) {
736 if (copy > have) copy =
have;
742 len + copy > state->
head->extra_max ?
743 state->
head->extra_max - len : copy);
745 if (state->
flags & 0x0200)
751 if (state->
length)
goto inf_leave;
756 if (state->
flags & 0x0800) {
757 if (have == 0)
goto inf_leave;
760 len = (unsigned)(next[copy++]);
765 }
while (len && copy < have);
766 if (state->
flags & 0x0200)
770 if (len)
goto inf_leave;
777 if (state->
flags & 0x1000) {
778 if (have == 0)
goto inf_leave;
781 len = (unsigned)(next[copy++]);
786 }
while (len && copy < have);
787 if (state->
flags & 0x0200)
791 if (len)
goto inf_leave;
797 if (state->
flags & 0x0200) {
799 if (hold != (state->
check & 0xffff)) {
800 strm->msg = (
char *)
"header crc mismatch";
807 state->
head->hcrc = (int)((state->
flags >> 9) & 1);
808 state->
head->done = 1;
839 Tracev((stderr,
"inflate: stored block%s\n",
840 state->
last ?
" (last)" :
""));
845 Tracev((stderr,
"inflate: fixed codes block%s\n",
846 state->
last ?
" (last)" :
""));
854 Tracev((stderr,
"inflate: dynamic codes block%s\n",
855 state->
last ?
" (last)" :
""));
859 strm->msg = (
char *)
"invalid block type";
867 if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
868 strm->msg = (
char *)
"invalid stored block lengths";
872 state->
length = (unsigned)hold & 0xffff;
873 Tracev((stderr,
"inflate: stored length %u\n",
877 if (flush ==
Z_TREES)
goto inf_leave;
883 if (copy > have) copy =
have;
884 if (copy > left) copy = left;
885 if (copy == 0)
goto inf_leave;
894 Tracev((stderr,
"inflate: stored end\n"));
905 #ifndef PKZIP_BUG_WORKAROUND
906 if (state->
nlen > 286 || state->
ndist > 30) {
907 strm->msg = (
char *)
"too many length or distance symbols";
912 Tracev((stderr,
"inflate: table sizes ok\n"));
918 state->
lens[order[state->
have++]] = (
unsigned short)
BITS(3);
921 while (state->
have < 19)
922 state->
lens[order[state->
have++]] = 0;
929 strm->msg = (
char *)
"invalid code lengths set";
933 Tracev((stderr,
"inflate: code lengths ok\n"));
940 if ((
unsigned)(here.
bits) <= bits)
break;
948 if (here.
val == 16) {
951 if (state->
have == 0) {
952 strm->msg = (
char *)
"invalid bit length repeat";
960 else if (here.
val == 17) {
975 strm->msg = (
char *)
"invalid bit length repeat";
980 state->
lens[state->
have++] = (
unsigned short)len;
988 if (state->
lens[256] == 0) {
989 strm->msg = (
char *)
"invalid code -- missing end-of-block";
1003 strm->msg = (
char *)
"invalid literal/lengths set";
1012 strm->msg = (
char *)
"invalid distances set";
1016 Tracev((stderr,
"inflate: codes ok\n"));
1018 if (flush ==
Z_TREES)
goto inf_leave;
1022 if (have >= 6 && left >= 258) {
1033 if ((
unsigned)(here.
bits) <= bits)
break;
1036 if (here.
op && (here.
op & 0xf0) == 0) {
1041 if ((
unsigned)(last.
bits + here.
bits) <= bits)
break;
1050 if ((
int)(here.
op) == 0) {
1052 "inflate: literal '%c'\n" :
1053 "inflate: literal 0x%02x\n", here.
val));
1058 Tracevv((stderr,
"inflate: end of block\n"));
1064 strm->msg = (
char *)
"invalid literal/length code";
1068 state->
extra = (unsigned)(here.
op) & 15;
1083 if ((
unsigned)(here.
bits) <= bits)
break;
1086 if ((here.
op & 0xf0) == 0) {
1091 if ((
unsigned)(last.
bits + here.
bits) <= bits)
break;
1100 strm->msg = (
char *)
"invalid distance code";
1105 state->
extra = (
unsigned)(here.
op) & 15;
1114 #ifdef INFLATE_STRICT
1116 strm->msg = (
char *)
"invalid distance too far back";
1124 if (left == 0)
goto inf_leave;
1126 if (state->
offset > copy) {
1127 copy = state->
offset - copy;
1128 if (copy > state->
whave) {
1130 strm->msg = (
char *)
"invalid distance too far back";
1134 #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1135 Trace((stderr,
"inflate.c too far\n"));
1136 copy -= state->
whave;
1138 if (copy > left) copy = left;
1148 if (copy > state->
wnext) {
1149 copy -= state->
wnext;
1157 from = put - state->
offset;
1160 if (copy > left) copy = left;
1169 if (left == 0)
goto inf_leave;
1170 *put++ = (
unsigned char)(state->
length);
1178 strm->total_out += out;
1179 state->
total += out;
1181 strm->adler = state->
check =
1186 state->
flags ? hold :
1189 strm->msg = (
char *)
"incorrect data check";
1194 Tracev((stderr,
"inflate: check matches trailer\n"));
1201 if (hold != (state->
total & 0xffffffffUL)) {
1202 strm->msg = (
char *)
"incorrect length check";
1207 Tracev((stderr,
"inflate: length matches trailer\n"));
1232 if (state->
wsize || (out != strm->avail_out && state->
mode <
BAD &&
1234 if (
updatewindow(strm, strm->next_out, out - strm->avail_out)) {
1238 in -= strm->avail_in;
1239 out -= strm->avail_out;
1240 strm->total_in += in;
1241 strm->total_out += out;
1242 state->
total += out;
1243 if (state->
wrap && out)
1244 strm->adler = state->
check =
1246 strm->data_type = state->
bits + (state->
last ? 64 : 0) +
1249 if (((in == 0 && out == 0) || flush ==
Z_FINISH) && ret ==
Z_OK)
code const FAR * distcode
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)
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
#define UPDATE(check, buf, len)
void ZLIB_INTERNAL zmemcpy(Bytef *dest, const Bytef *source, uInt len)
uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
local void fixedtables(struct inflate_state FAR *state)
unsigned char FAR * window
#define CRC4(check, word)
local int updatewindow(z_streamp strm, const Bytef *end, unsigned copy)