625{
627 z_const
unsigned char FAR *
next;
628 unsigned char FAR *put;
632 unsigned in, out;
634 unsigned char FAR *from;
637 unsigned len;
638 int ret;
639#ifdef GUNZIP
640 unsigned char hbuf[4];
641#endif
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};
644
648
653 out = left;
655 for (;;)
656 switch (state->
mode) {
658 if (state->
wrap == 0) {
660 break;
661 }
663#ifdef GUNZIP
664 if ((state->
wrap & 2) &&
hold == 0x8b1f) {
665 if (state->
wbits == 0)
671 break;
672 }
675 state->
head->done = -1;
676 if (!(state->
wrap & 1) ||
677#else
678 if (
679#endif
680 ((
BITS(8) << 8) + (
hold >> 8)) % 31) {
681 strm->msg = (
char *)
"incorrect header check";
683 break;
684 }
686 strm->msg = (
char *)
"unknown compression method";
688 break;
689 }
692 if (state->
wbits == 0)
694 if (len > 15 || len > state->
wbits) {
695 strm->msg = (
char *)
"invalid window size";
697 break;
698 }
699 state->
dmax = 1U << len;
700 Tracev((stderr,
"inflate: zlib header ok\n"));
704 break;
705#ifdef GUNZIP
710 strm->msg = (
char *)
"unknown compression method";
712 break;
713 }
714 if (state->
flags & 0xe000) {
715 strm->msg = (
char *)
"unknown header flags set";
717 break;
718 }
720 state->
head->text = (int)((
hold >> 8) & 1);
721 if ((state->
flags & 0x0200) && (state->
wrap & 4))
729 if ((state->
flags & 0x0200) && (state->
wrap & 4))
736 state->
head->xflags = (int)(
hold & 0xff);
738 }
739 if ((state->
flags & 0x0200) && (state->
wrap & 4))
744 if (state->
flags & 0x0400) {
748 state->
head->extra_len = (unsigned)
hold;
749 if ((state->
flags & 0x0200) && (state->
wrap & 4))
752 }
757 if (state->
flags & 0x0400) {
760 if (copy) {
765 len + copy > state->
head->extra_max ?
766 state->
head->extra_max - len : copy);
767 }
768 if ((state->
flags & 0x0200) && (state->
wrap & 4))
773 }
774 if (state->
length)
goto inf_leave;
775 }
779 if (state->
flags & 0x0800) {
780 if (
have == 0)
goto inf_leave;
782 do {
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;
794 }
800 if (state->
flags & 0x1000) {
801 if (
have == 0)
goto inf_leave;
803 do {
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;
815 }
820 if (state->
flags & 0x0200) {
823 strm->msg = (
char *)
"header crc mismatch";
825 break;
826 }
828 }
830 state->
head->hcrc = (int)((state->
flags >> 9) & 1);
831 state->
head->done = 1;
832 }
835 break;
836#endif
846 }
855 break;
856 }
861 case 0:
862 Tracev((stderr,
"inflate: stored block%s\n",
863 state->
last ?
" (last)" :
""));
865 break;
866 case 1:
868 Tracev((stderr,
"inflate: fixed codes block%s\n",
869 state->
last ?
" (last)" :
""));
873 goto inf_leave;
874 }
875 break;
876 case 2:
877 Tracev((stderr,
"inflate: dynamic codes block%s\n",
878 state->
last ?
" (last)" :
""));
880 break;
881 case 3:
882 strm->msg = (
char *)
"invalid block type";
884 }
886 break;
890 if ((
hold & 0xffff) != ((
hold >> 16) ^ 0xffff)) {
891 strm->msg = (
char *)
"invalid stored block lengths";
893 break;
894 }
896 Tracev((stderr,
"inflate: stored length %u\n",
900 if (flush ==
Z_TREES)
goto inf_leave;
905 if (copy) {
907 if (copy > left)
copy = left;
908 if (copy == 0) goto inf_leave;
915 break;
916 }
917 Tracev((stderr,
"inflate: stored end\n"));
919 break;
928#ifndef PKZIP_BUG_WORKAROUND
929 if (state->
nlen > 286 || state->
ndist > 30) {
930 strm->msg = (
char *)
"too many length or distance symbols";
932 break;
933 }
934#endif
935 Tracev((stderr,
"inflate: table sizes ok\n"));
941 state->
lens[order[state->
have++]] = (
unsigned short)
BITS(3);
943 }
944 while (state->
have < 19)
945 state->
lens[order[state->
have++]] = 0;
951 if (ret) {
952 strm->msg = (
char *)
"invalid code lengths set";
954 break;
955 }
956 Tracev((stderr,
"inflate: code lengths ok\n"));
961 for (;;) {
963 if ((
unsigned)(here.
bits) <=
bits)
break;
965 }
969 }
970 else {
971 if (here.
val == 16) {
974 if (state->
have == 0) {
975 strm->msg = (
char *)
"invalid bit length repeat";
977 break;
978 }
982 }
983 else if (here.
val == 17) {
986 len = 0;
989 }
990 else {
993 len = 0;
996 }
998 strm->msg = (
char *)
"invalid bit length repeat";
1000 break;
1001 }
1002 while (copy--)
1003 state->
lens[state->
have++] = (
unsigned short)len;
1004 }
1005 }
1006
1007
1008 if (state->
mode ==
BAD)
break;
1009
1010
1011 if (state->
lens[256] == 0) {
1012 strm->msg = (
char *)
"invalid code -- missing end-of-block";
1014 break;
1015 }
1016
1017
1018
1019
1025 if (ret) {
1026 strm->msg = (
char *)
"invalid literal/lengths set";
1028 break;
1029 }
1034 if (ret) {
1035 strm->msg = (
char *)
"invalid distances set";
1037 break;
1038 }
1039 Tracev((stderr,
"inflate: codes ok\n"));
1041 if (flush ==
Z_TREES)
goto inf_leave;
1045 if (
have >= 6 && left >= 258) {
1051 break;
1052 }
1054 for (;;) {
1056 if ((
unsigned)(here.
bits) <=
bits)
break;
1058 }
1059 if (here.
op && (here.
op & 0xf0) == 0) {
1061 for (;;) {
1066 }
1069 }
1073 if ((
int)(here.
op) == 0) {
1075 "inflate: literal '%c'\n" :
1076 "inflate: literal 0x%02x\n", here.
val));
1078 break;
1079 }
1081 Tracevv((stderr,
"inflate: end of block\n"));
1084 break;
1085 }
1087 strm->msg = (
char *)
"invalid literal/length code";
1089 break;
1090 }
1091 state->
extra = (unsigned)(here.
op) & 15;
1099 }
1104 for (;;) {
1106 if ((
unsigned)(here.
bits) <=
bits)
break;
1108 }
1109 if ((here.
op & 0xf0) == 0) {
1111 for (;;) {
1116 }
1119 }
1123 strm->msg = (
char *)
"invalid distance code";
1125 break;
1126 }
1128 state->
extra = (
unsigned)(here.
op) & 15;
1136 }
1137#ifdef INFLATE_STRICT
1139 strm->msg = (
char *)
"invalid distance too far back";
1141 break;
1142 }
1143#endif
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";
1155 break;
1156 }
1157#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1158 Trace((stderr,
"inflate.c too far\n"));
1161 if (copy > left)
copy = left;
1164 do {
1165 *put++ = 0;
1166 } while (--copy);
1168 break;
1169#endif
1170 }
1171 if (copy > state->
wnext) {
1174 }
1175 else
1178 }
1179 else {
1180 from = put - state->
offset;
1182 }
1183 if (copy > left)
copy = left;
1186 do {
1187 *put++ = *from++;
1188 } while (--copy);
1190 break;
1192 if (left == 0) goto inf_leave;
1193 *put++ = (
unsigned char)(state->
length);
1194 left--;
1196 break;
1200 out -= left;
1201 strm->total_out += out;
1202 state->
total += out;
1203 if ((state->
wrap & 4) && out)
1206 out = left;
1207 if ((state->
wrap & 4) && (
1210#endif
1212 strm->msg = (
char *)
"incorrect data check";
1214 break;
1215 }
1217 Tracev((stderr,
"inflate: check matches trailer\n"));
1218 }
1219#ifdef GUNZIP
1224 if (
hold != (state->
total & 0xffffffffUL)) {
1225 strm->msg = (
char *)
"incorrect length check";
1227 break;
1228 }
1230 Tracev((stderr,
"inflate: length matches trailer\n"));
1231 }
1232#endif
1236 goto inf_leave;
1239 goto inf_leave;
1243 default:
1245 }
1246
1247
1248
1249
1250
1251
1252
1253 inf_leave:
1260 }
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)
1269 strm->data_type = (int)state->
bits + (state->
last ? 64 : 0) +
1272 if (((in == 0 && out == 0) || flush ==
Z_FINISH) && ret ==
Z_OK)
1274 return ret;
1275}
uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start)
void fixedtables(struct inflate_state FAR *state)
#define UPDATE(check, buf, len)
int inflateStateCheck(z_streamp strm)
int updatewindow(z_streamp strm, const Bytef *end, unsigned copy)
void copy(G4double dst[], const G4double src[], size_t size=G4FieldTrack::ncompSVEC)
code const FAR * distcode
unsigned char FAR * window
void ZLIB_INTERNAL zmemcpy(Bytef *dest, const Bytef *source, uInt len)