584 unsigned char FAR *put;
590 unsigned char FAR *from;
596 unsigned char hbuf[4];
598 static const unsigned short order[19] =
599 {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
602 (strm->next_in ==
Z_NULL && strm->avail_in != 0))
612 switch (state->
mode) {
614 if (state->
wrap == 0) {
620 if ((state->
wrap & 2) && hold == 0x8b1f) {
629 state->
head->done = -1;
630 if (!(state->
wrap & 1) ||
634 ((
BITS(8) << 8) + (hold >> 8)) % 31) {
635 strm->msg = (
char *)
"incorrect header check";
640 strm->msg = (
char *)
"unknown compression method";
646 if (state->
wbits == 0)
648 else if (len > state->
wbits) {
649 strm->msg = (
char *)
"invalid window size";
653 state->
dmax = 1U << len;
654 Tracev((stderr,
"inflate: zlib header ok\n"));
662 state->
flags = (int)(hold);
664 strm->msg = (
char *)
"unknown compression method";
668 if (state->
flags & 0xe000) {
669 strm->msg = (
char *)
"unknown header flags set";
674 state->
head->text = (int)((hold >> 8) & 1);
688 state->
head->xflags = (int)(hold & 0xff);
689 state->
head->os = (int)(hold >> 8);
695 if (state->
flags & 0x0400) {
697 state->
length = (unsigned)(hold);
699 state->
head->extra_len = (unsigned)hold;
707 if (state->
flags & 0x0400) {
709 if (copy > have) copy =
have;
715 len + copy > state->
head->extra_max ?
716 state->
head->extra_max - len : copy);
718 if (state->
flags & 0x0200)
724 if (state->
length)
goto inf_leave;
729 if (state->
flags & 0x0800) {
730 if (have == 0)
goto inf_leave;
733 len = (unsigned)(next[copy++]);
738 }
while (len && copy < have);
739 if (state->
flags & 0x0200)
743 if (len)
goto inf_leave;
750 if (state->
flags & 0x1000) {
751 if (have == 0)
goto inf_leave;
754 len = (unsigned)(next[copy++]);
759 }
while (len && copy < have);
760 if (state->
flags & 0x0200)
764 if (len)
goto inf_leave;
770 if (state->
flags & 0x0200) {
772 if (hold != (state->
check & 0xffff)) {
773 strm->msg = (
char *)
"header crc mismatch";
780 state->
head->hcrc = (int)((state->
flags >> 9) & 1);
781 state->
head->done = 1;
812 Tracev((stderr,
"inflate: stored block%s\n",
813 state->
last ?
" (last)" :
""));
818 Tracev((stderr,
"inflate: fixed codes block%s\n",
819 state->
last ?
" (last)" :
""));
827 Tracev((stderr,
"inflate: dynamic codes block%s\n",
828 state->
last ?
" (last)" :
""));
832 strm->msg = (
char *)
"invalid block type";
840 if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
841 strm->msg = (
char *)
"invalid stored block lengths";
845 state->
length = (unsigned)hold & 0xffff;
846 Tracev((stderr,
"inflate: stored length %u\n",
850 if (flush ==
Z_TREES)
goto inf_leave;
856 if (copy > have) copy =
have;
857 if (copy > left) copy = left;
858 if (copy == 0)
goto inf_leave;
867 Tracev((stderr,
"inflate: stored end\n"));
878 #ifndef PKZIP_BUG_WORKAROUND
879 if (state->
nlen > 286 || state->
ndist > 30) {
880 strm->msg = (
char *)
"too many length or distance symbols";
885 Tracev((stderr,
"inflate: table sizes ok\n"));
891 state->
lens[order[state->
have++]] = (
unsigned short)
BITS(3);
894 while (state->
have < 19)
895 state->
lens[order[state->
have++]] = 0;
902 strm->msg = (
char *)
"invalid code lengths set";
906 Tracev((stderr,
"inflate: code lengths ok\n"));
913 if ((
unsigned)(here.
bits) <= bits)
break;
922 if (here.
val == 16) {
925 if (state->
have == 0) {
926 strm->msg = (
char *)
"invalid bit length repeat";
934 else if (here.
val == 17) {
949 strm->msg = (
char *)
"invalid bit length repeat";
954 state->
lens[state->
have++] = (
unsigned short)len;
962 if (state->
lens[256] == 0) {
963 strm->msg = (
char *)
"invalid code -- missing end-of-block";
977 strm->msg = (
char *)
"invalid literal/lengths set";
986 strm->msg = (
char *)
"invalid distances set";
990 Tracev((stderr,
"inflate: codes ok\n"));
992 if (flush ==
Z_TREES)
goto inf_leave;
996 if (have >= 6 && left >= 258) {
1007 if ((
unsigned)(here.
bits) <= bits)
break;
1010 if (here.
op && (here.
op & 0xf0) == 0) {
1015 if ((
unsigned)(last.
bits + here.
bits) <= bits)
break;
1024 if ((
int)(here.
op) == 0) {
1026 "inflate: literal '%c'\n" :
1027 "inflate: literal 0x%02x\n", here.
val));
1032 Tracevv((stderr,
"inflate: end of block\n"));
1038 strm->msg = (
char *)
"invalid literal/length code";
1042 state->
extra = (unsigned)(here.
op) & 15;
1057 if ((
unsigned)(here.
bits) <= bits)
break;
1060 if ((here.
op & 0xf0) == 0) {
1065 if ((
unsigned)(last.
bits + here.
bits) <= bits)
break;
1074 strm->msg = (
char *)
"invalid distance code";
1079 state->
extra = (
unsigned)(here.
op) & 15;
1088 #ifdef INFLATE_STRICT
1090 strm->msg = (
char *)
"invalid distance too far back";
1098 if (left == 0)
goto inf_leave;
1100 if (state->
offset > copy) {
1102 if (copy > state->
whave) {
1104 strm->msg = (
char *)
"invalid distance too far back";
1108 #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1109 Trace((stderr,
"inflate.c too far\n"));
1110 copy -= state->
whave;
1112 if (copy > left) copy = left;
1122 if (copy > state->
wnext) {
1123 copy -= state->
wnext;
1131 from = put - state->
offset;
1134 if (copy > left) copy = left;
1143 if (left == 0)
goto inf_leave;
1144 *put++ = (
unsigned char)(state->
length);
1152 strm->total_out += out;
1153 state->
total += out;
1155 strm->adler = state->
check =
1160 state->
flags ? hold :
1163 strm->msg = (
char *)
"incorrect data check";
1168 Tracev((stderr,
"inflate: check matches trailer\n"));
1175 if (hold != (state->
total & 0xffffffffUL)) {
1176 strm->msg = (
char *)
"incorrect length check";
1181 Tracev((stderr,
"inflate: length matches trailer\n"));
1206 if (state->
wsize || (state->
mode <
CHECK && out != strm->avail_out))
1211 in -= strm->avail_in;
1212 out -= strm->avail_out;
1213 strm->total_in += in;
1214 strm->total_out += out;
1215 state->
total += out;
1216 if (state->
wrap && out)
1217 strm->adler = state->
check =
1219 strm->data_type = state->
bits + (state->
last ? 64 : 0) +
1222 if (((in == 0 && out == 0) || flush ==
Z_FINISH) && ret ==
Z_OK)
static void copy(const T &from, T &to)
local void fixedtables(struct inflate_state FAR *state)
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)
local int updatewindow(z_streamp strm, unsigned out)
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)
unsigned char FAR * window
#define CRC4(check, word)
static char * bits(int n)