590 z_const
unsigned char FAR *
next;
591 unsigned char FAR *put;
597 unsigned char FAR *from;
603 unsigned char hbuf[4];
605 static const unsigned short order[19] =
606 {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
609 (strm->next_in ==
Z_NULL && strm->avail_in != 0))
619 switch (state->
mode) {
621 if (state->
wrap == 0) {
627 if ((state->
wrap & 2) && hold == 0x8b1f) {
636 state->
head->done = -1;
637 if (!(state->
wrap & 1) ||
641 ((
BITS(8) << 8) + (hold >> 8)) % 31) {
642 strm->msg = (
char *)
"incorrect header check";
647 strm->msg = (
char *)
"unknown compression method";
653 if (state->
wbits == 0)
655 else if (len > state->
wbits) {
656 strm->msg = (
char *)
"invalid window size";
660 state->
dmax = 1U << len;
661 Tracev((stderr,
"inflate: zlib header ok\n"));
669 state->
flags = (int)(hold);
671 strm->msg = (
char *)
"unknown compression method";
675 if (state->
flags & 0xe000) {
676 strm->msg = (
char *)
"unknown header flags set";
681 state->
head->text = (int)((hold >> 8) & 1);
695 state->
head->xflags = (int)(hold & 0xff);
696 state->
head->os = (int)(hold >> 8);
702 if (state->
flags & 0x0400) {
704 state->
length = (unsigned)(hold);
706 state->
head->extra_len = (unsigned)hold;
714 if (state->
flags & 0x0400) {
716 if (copy > have) copy =
have;
722 len + copy > state->
head->extra_max ?
723 state->
head->extra_max - len : copy);
725 if (state->
flags & 0x0200)
731 if (state->
length)
goto inf_leave;
736 if (state->
flags & 0x0800) {
737 if (have == 0)
goto inf_leave;
740 len = (unsigned)(next[copy++]);
745 }
while (len && copy < have);
746 if (state->
flags & 0x0200)
750 if (len)
goto inf_leave;
757 if (state->
flags & 0x1000) {
758 if (have == 0)
goto inf_leave;
761 len = (unsigned)(next[copy++]);
766 }
while (len && copy < have);
767 if (state->
flags & 0x0200)
771 if (len)
goto inf_leave;
777 if (state->
flags & 0x0200) {
779 if (hold != (state->
check & 0xffff)) {
780 strm->msg = (
char *)
"header crc mismatch";
787 state->
head->hcrc = (int)((state->
flags >> 9) & 1);
788 state->
head->done = 1;
819 Tracev((stderr,
"inflate: stored block%s\n",
820 state->
last ?
" (last)" :
""));
825 Tracev((stderr,
"inflate: fixed codes block%s\n",
826 state->
last ?
" (last)" :
""));
834 Tracev((stderr,
"inflate: dynamic codes block%s\n",
835 state->
last ?
" (last)" :
""));
839 strm->msg = (
char *)
"invalid block type";
847 if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
848 strm->msg = (
char *)
"invalid stored block lengths";
852 state->
length = (unsigned)hold & 0xffff;
853 Tracev((stderr,
"inflate: stored length %u\n",
857 if (flush ==
Z_TREES)
goto inf_leave;
863 if (copy > have) copy =
have;
864 if (copy > left) copy =
left;
865 if (copy == 0)
goto inf_leave;
874 Tracev((stderr,
"inflate: stored end\n"));
885 #ifndef PKZIP_BUG_WORKAROUND 886 if (state->
nlen > 286 || state->
ndist > 30) {
887 strm->msg = (
char *)
"too many length or distance symbols";
892 Tracev((stderr,
"inflate: table sizes ok\n"));
898 state->
lens[order[state->
have++]] = (
unsigned short)
BITS(3);
901 while (state->
have < 19)
902 state->
lens[order[state->
have++]] = 0;
909 strm->msg = (
char *)
"invalid code lengths set";
913 Tracev((stderr,
"inflate: code lengths ok\n"));
920 if ((
unsigned)(here.
bits) <= bits)
break;
928 if (here.
val == 16) {
931 if (state->
have == 0) {
932 strm->msg = (
char *)
"invalid bit length repeat";
940 else if (here.
val == 17) {
955 strm->msg = (
char *)
"invalid bit length repeat";
960 state->
lens[state->
have++] = (
unsigned short)len;
968 if (state->
lens[256] == 0) {
969 strm->msg = (
char *)
"invalid code -- missing end-of-block";
983 strm->msg = (
char *)
"invalid literal/lengths set";
992 strm->msg = (
char *)
"invalid distances set";
996 Tracev((stderr,
"inflate: codes ok\n"));
998 if (flush ==
Z_TREES)
goto inf_leave;
1002 if (have >= 6 && left >= 258) {
1013 if ((
unsigned)(here.
bits) <= bits)
break;
1016 if (here.
op && (here.
op & 0xf0) == 0) {
1021 if ((
unsigned)(last.
bits + here.
bits) <= bits)
break;
1030 if ((
int)(here.
op) == 0) {
1032 "inflate: literal '%c'\n" :
1033 "inflate: literal 0x%02x\n", here.
val));
1038 Tracevv((stderr,
"inflate: end of block\n"));
1044 strm->msg = (
char *)
"invalid literal/length code";
1048 state->
extra = (unsigned)(here.
op) & 15;
1063 if ((
unsigned)(here.
bits) <= bits)
break;
1066 if ((here.
op & 0xf0) == 0) {
1071 if ((
unsigned)(last.
bits + here.
bits) <= bits)
break;
1080 strm->msg = (
char *)
"invalid distance code";
1085 state->
extra = (
unsigned)(here.
op) & 15;
1094 #ifdef INFLATE_STRICT 1096 strm->msg = (
char *)
"invalid distance too far back";
1104 if (left == 0)
goto inf_leave;
1106 if (state->
offset > copy) {
1107 copy = state->
offset - copy;
1108 if (copy > state->
whave) {
1110 strm->msg = (
char *)
"invalid distance too far back";
1114 #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR 1115 Trace((stderr,
"inflate.c too far\n"));
1116 copy -= state->
whave;
1118 if (copy > left) copy =
left;
1128 if (copy > state->
wnext) {
1129 copy -= state->
wnext;
1137 from = put - state->
offset;
1140 if (copy > left) copy =
left;
1149 if (left == 0)
goto inf_leave;
1150 *put++ = (
unsigned char)(state->
length);
1158 strm->total_out += out;
1159 state->
total += out;
1161 strm->adler = state->
check =
1166 state->
flags ? hold :
1169 strm->msg = (
char *)
"incorrect data check";
1174 Tracev((stderr,
"inflate: check matches trailer\n"));
1181 if (hold != (state->
total & 0xffffffffUL)) {
1182 strm->msg = (
char *)
"incorrect length check";
1187 Tracev((stderr,
"inflate: length matches trailer\n"));
1212 if (state->
wsize || (out != strm->avail_out && state->
mode <
BAD &&
1214 if (
updatewindow(strm, strm->next_out, out - strm->avail_out)) {
1218 in -= strm->avail_in;
1219 out -= strm->avail_out;
1220 strm->total_in +=
in;
1221 strm->total_out += out;
1222 state->
total += out;
1223 if (state->
wrap && out)
1224 strm->adler = state->
check =
1226 strm->data_type = state->
bits + (state->
last ? 64 : 0) +
1229 if (((in == 0 && out == 0) || flush ==
Z_FINISH) && ret ==
Z_OK)
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)
void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start)
local int updatewindow(z_streamp strm, const Bytef *end, unsigned copy)
code const FAR * distcode
uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
void ZLIB_INTERNAL zmemcpy(Bytef *dest, const Bytef *source, uInt len)
#define CRC2(check, word)
#define UPDATE(check, buf, len)
#define CRC4(check, word)
unsigned char FAR * window
local void fixedtables(struct inflate_state FAR *state)