628{
630 z_const
unsigned char FAR *
next;
631 unsigned char FAR *put;
635 unsigned in, out;
637 unsigned char FAR *from;
640 unsigned len;
641 int ret;
642#ifdef GUNZIP
643 unsigned char hbuf[4];
644#endif
645 static const unsigned short order[19] =
646 {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
647
651
656 out = left;
658 for (;;)
659 switch (state->
mode) {
661 if (state->
wrap == 0) {
663 break;
664 }
666#ifdef GUNZIP
667 if ((state->
wrap & 2) &&
hold == 0x8b1f) {
668 if (state->
wbits == 0)
674 break;
675 }
677 state->
head->done = -1;
678 if (!(state->
wrap & 1) ||
679#else
680 if (
681#endif
682 ((
BITS(8) << 8) + (
hold >> 8)) % 31) {
683 strm->msg = (
char *)
"incorrect header check";
685 break;
686 }
688 strm->msg = (
char *)
"unknown compression method";
690 break;
691 }
694 if (state->
wbits == 0)
696 if (len > 15 || len > state->
wbits) {
697 strm->msg = (
char *)
"invalid window size";
699 break;
700 }
701 state->
dmax = 1U << len;
703 Tracev((stderr,
"inflate: zlib header ok\n"));
707 break;
708#ifdef GUNZIP
713 strm->msg = (
char *)
"unknown compression method";
715 break;
716 }
717 if (state->
flags & 0xe000) {
718 strm->msg = (
char *)
"unknown header flags set";
720 break;
721 }
723 state->
head->text = (int)((
hold >> 8) & 1);
724 if ((state->
flags & 0x0200) && (state->
wrap & 4))
728
733 if ((state->
flags & 0x0200) && (state->
wrap & 4))
737
741 state->
head->xflags = (int)(
hold & 0xff);
743 }
744 if ((state->
flags & 0x0200) && (state->
wrap & 4))
748
750 if (state->
flags & 0x0400) {
754 state->
head->extra_len = (unsigned)
hold;
755 if ((state->
flags & 0x0200) && (state->
wrap & 4))
758 }
762
764 if (state->
flags & 0x0400) {
767 if (copy) {
770 (len = state->
head->extra_len - state->
length) <
771 state->
head->extra_max) {
773 len + copy > state->
head->extra_max ?
774 state->
head->extra_max - len : copy);
775 }
776 if ((state->
flags & 0x0200) && (state->
wrap & 4))
781 }
782 if (state->
length)
goto inf_leave;
783 }
786
788 if (state->
flags & 0x0800) {
789 if (
have == 0)
goto inf_leave;
791 do {
792 len = (unsigned)(
next[copy++]);
796 state->
head->name[state->
length++] = (Bytef)len;
797 }
while (len && copy <
have);
798 if ((state->
flags & 0x0200) && (state->
wrap & 4))
802 if (len) goto inf_leave;
803 }
808
810 if (state->
flags & 0x1000) {
811 if (
have == 0)
goto inf_leave;
813 do {
814 len = (unsigned)(
next[copy++]);
818 state->
head->comment[state->
length++] = (Bytef)len;
819 }
while (len && copy <
have);
820 if ((state->
flags & 0x0200) && (state->
wrap & 4))
824 if (len) goto inf_leave;
825 }
829
831 if (state->
flags & 0x0200) {
834 strm->msg = (
char *)
"header crc mismatch";
836 break;
837 }
839 }
841 state->
head->hcrc = (int)((state->
flags >> 9) & 1);
842 state->
head->done = 1;
843 }
846 break;
847#endif
853
858 }
861
864
869 break;
870 }
875 case 0:
876 Tracev((stderr,
"inflate: stored block%s\n",
877 state->
last ?
" (last)" :
""));
879 break;
880 case 1:
882 Tracev((stderr,
"inflate: fixed codes block%s\n",
883 state->
last ?
" (last)" :
""));
887 goto inf_leave;
888 }
889 break;
890 case 2:
891 Tracev((stderr,
"inflate: dynamic codes block%s\n",
892 state->
last ?
" (last)" :
""));
894 break;
895 case 3:
896 strm->msg = (
char *)
"invalid block type";
898 }
900 break;
904 if ((
hold & 0xffff) != ((
hold >> 16) ^ 0xffff)) {
905 strm->msg = (
char *)
"invalid stored block lengths";
907 break;
908 }
910 Tracev((stderr,
"inflate: stored length %u\n",
914 if (flush ==
Z_TREES)
goto inf_leave;
915
918
921 if (copy) {
923 if (copy > left)
copy = left;
924 if (copy == 0) goto inf_leave;
931 break;
932 }
933 Tracev((stderr,
"inflate: stored end\n"));
935 break;
944#ifndef PKZIP_BUG_WORKAROUND
945 if (state->
nlen > 286 || state->
ndist > 30) {
946 strm->msg = (
char *)
"too many length or distance symbols";
948 break;
949 }
950#endif
951 Tracev((stderr,
"inflate: table sizes ok\n"));
954
958 state->
lens[order[state->
have++]] = (
unsigned short)
BITS(3);
960 }
961 while (state->
have < 19)
962 state->
lens[order[state->
have++]] = 0;
968 if (ret) {
969 strm->msg = (
char *)
"invalid code lengths set";
971 break;
972 }
973 Tracev((stderr,
"inflate: code lengths ok\n"));
976
979 for (;;) {
981 if ((
unsigned)(here.
bits) <=
bits)
break;
983 }
987 }
988 else {
989 if (here.
val == 16) {
992 if (state->
have == 0) {
993 strm->msg = (
char *)
"invalid bit length repeat";
995 break;
996 }
1000 }
1001 else if (here.
val == 17) {
1004 len = 0;
1007 }
1008 else {
1011 len = 0;
1014 }
1016 strm->msg = (
char *)
"invalid bit length repeat";
1018 break;
1019 }
1020 while (copy--)
1021 state->
lens[state->
have++] = (
unsigned short)len;
1022 }
1023 }
1024
1025
1026 if (state->
mode ==
BAD)
break;
1027
1028
1029 if (state->
lens[256] == 0) {
1030 strm->msg = (
char *)
"invalid code -- missing end-of-block";
1032 break;
1033 }
1034
1035
1036
1037
1043 if (ret) {
1044 strm->msg = (
char *)
"invalid literal/lengths set";
1046 break;
1047 }
1052 if (ret) {
1053 strm->msg = (
char *)
"invalid distances set";
1055 break;
1056 }
1057 Tracev((stderr,
"inflate: codes ok\n"));
1059 if (flush ==
Z_TREES)
goto inf_leave;
1060
1063
1065 if (
have >= 6 && left >= 258) {
1071 break;
1072 }
1074 for (;;) {
1076 if ((
unsigned)(here.
bits) <=
bits)
break;
1078 }
1079 if (here.
op && (here.
op & 0xf0) == 0) {
1081 for (;;) {
1086 }
1089 }
1093 if ((
int)(here.
op) == 0) {
1095 "inflate: literal '%c'\n" :
1096 "inflate: literal 0x%02x\n", here.
val));
1098 break;
1099 }
1101 Tracevv((stderr,
"inflate: end of block\n"));
1104 break;
1105 }
1107 strm->msg = (
char *)
"invalid literal/length code";
1109 break;
1110 }
1111 state->
extra = (unsigned)(here.
op) & 15;
1113
1120 }
1124
1126 for (;;) {
1128 if ((
unsigned)(here.
bits) <=
bits)
break;
1130 }
1131 if ((here.
op & 0xf0) == 0) {
1133 for (;;) {
1138 }
1141 }
1145 strm->msg = (
char *)
"invalid distance code";
1147 break;
1148 }
1150 state->
extra = (unsigned)(here.
op) & 15;
1152
1159 }
1160#ifdef INFLATE_STRICT
1162 strm->msg = (
char *)
"invalid distance too far back";
1164 break;
1165 }
1166#endif
1169
1171 if (left == 0) goto inf_leave;
1173 if (state->
offset > copy) {
1175 if (copy > state->
whave) {
1177 strm->msg = (
char *)
"invalid distance too far back";
1179 break;
1180 }
1181#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1182 Trace((stderr,
"inflate.c too far\n"));
1185 if (copy > left)
copy = left;
1188 do {
1189 *put++ = 0;
1190 } while (--copy);
1192 break;
1193#endif
1194 }
1195 if (copy > state->
wnext) {
1198 }
1199 else
1202 }
1203 else {
1204 from = put - state->
offset;
1206 }
1207 if (copy > left)
copy = left;
1210 do {
1211 *put++ = *from++;
1212 } while (--copy);
1214 break;
1216 if (left == 0) goto inf_leave;
1217 *put++ = (
unsigned char)(state->
length);
1218 left--;
1220 break;
1224 out -= left;
1225 strm->total_out += out;
1226 state->
total += out;
1227 if ((state->
wrap & 4) && out)
1230 out = left;
1231 if ((state->
wrap & 4) && (
1234#endif
1236 strm->msg = (
char *)
"incorrect data check";
1238 break;
1239 }
1241 Tracev((stderr,
"inflate: check matches trailer\n"));
1242 }
1243#ifdef GUNZIP
1245
1249 if ((state->
wrap & 4) &&
hold != (state->
total & 0xffffffff)) {
1250 strm->msg = (
char *)
"incorrect length check";
1252 break;
1253 }
1255 Tracev((stderr,
"inflate: length matches trailer\n"));
1256 }
1257#endif
1259
1262 goto inf_leave;
1265 goto inf_leave;
1269
1270 default:
1272 }
1273
1274
1275
1276
1277
1278
1279
1280 inf_leave:
1287 }
1288 in -=
strm->avail_in;
1289 out -=
strm->avail_out;
1290 strm->total_in += in;
1291 strm->total_out += out;
1292 state->
total += out;
1293 if ((state->
wrap & 4) && out)
1296 strm->data_type = (int)state->
bits + (state->
last ? 64 : 0) +
1299 if (((in == 0 && out == 0) || flush ==
Z_FINISH) && ret ==
Z_OK)
1301 return ret;
1302}
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 inflateStateCheck(z_streamp strm)
local void fixedtables(struct inflate_state FAR *state)
local int updatewindow(z_streamp strm, const Bytef *end, unsigned copy)
#define UPDATE_CHECK(check, buf, len)
void copy(G4double dst[], const G4double src[], std::size_t size=G4FieldTrack::ncompSVEC)
code const FAR * distcode
unsigned char FAR * window
void ZLIB_INTERNAL zmemcpy(Bytef *dest, const Bytef *source, uInt len)