626{
628 z_const
unsigned char FAR *
next;
629 unsigned char FAR *put;
633 unsigned in, out;
635 unsigned char FAR *from;
638 unsigned len;
639 int ret;
640#ifdef GUNZIP
641 unsigned char hbuf[4];
642#endif
643 static const unsigned short order[19] =
644 {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
645
649
654 out = left;
656 for (;;)
657 switch (state->
mode) {
659 if (state->
wrap == 0) {
661 break;
662 }
664#ifdef GUNZIP
665 if ((state->
wrap & 2) &&
hold == 0x8b1f) {
666 if (state->
wbits == 0)
672 break;
673 }
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;
701 Tracev((stderr,
"inflate: zlib header ok\n"));
705 break;
706#ifdef GUNZIP
711 strm->msg = (
char *)
"unknown compression method";
713 break;
714 }
715 if (state->
flags & 0xe000) {
716 strm->msg = (
char *)
"unknown header flags set";
718 break;
719 }
721 state->
head->text = (int)((
hold >> 8) & 1);
722 if ((state->
flags & 0x0200) && (state->
wrap & 4))
726
731 if ((state->
flags & 0x0200) && (state->
wrap & 4))
735
739 state->
head->xflags = (int)(
hold & 0xff);
741 }
742 if ((state->
flags & 0x0200) && (state->
wrap & 4))
746
748 if (state->
flags & 0x0400) {
752 state->
head->extra_len = (unsigned)
hold;
753 if ((state->
flags & 0x0200) && (state->
wrap & 4))
756 }
760
762 if (state->
flags & 0x0400) {
765 if (copy) {
770 len + copy > state->
head->extra_max ?
771 state->
head->extra_max - len : copy);
772 }
773 if ((state->
flags & 0x0200) && (state->
wrap & 4))
778 }
779 if (state->
length)
goto inf_leave;
780 }
783
785 if (state->
flags & 0x0800) {
786 if (
have == 0)
goto inf_leave;
788 do {
789 len = (unsigned)(
next[copy++]);
793 state->
head->name[state->
length++] = (Bytef)len;
794 }
while (len && copy <
have);
795 if ((state->
flags & 0x0200) && (state->
wrap & 4))
799 if (len) goto inf_leave;
800 }
805
807 if (state->
flags & 0x1000) {
808 if (
have == 0)
goto inf_leave;
810 do {
811 len = (unsigned)(
next[copy++]);
815 state->
head->comment[state->
length++] = (Bytef)len;
816 }
while (len && copy <
have);
817 if ((state->
flags & 0x0200) && (state->
wrap & 4))
821 if (len) goto inf_leave;
822 }
826
828 if (state->
flags & 0x0200) {
831 strm->msg = (
char *)
"header crc mismatch";
833 break;
834 }
836 }
838 state->
head->hcrc = (int)((state->
flags >> 9) & 1);
839 state->
head->done = 1;
840 }
843 break;
844#endif
850
855 }
858
861
866 break;
867 }
872 case 0:
873 Tracev((stderr,
"inflate: stored block%s\n",
874 state->
last ?
" (last)" :
""));
876 break;
877 case 1:
879 Tracev((stderr,
"inflate: fixed codes block%s\n",
880 state->
last ?
" (last)" :
""));
884 goto inf_leave;
885 }
886 break;
887 case 2:
888 Tracev((stderr,
"inflate: dynamic codes block%s\n",
889 state->
last ?
" (last)" :
""));
891 break;
892 case 3:
893 strm->msg = (
char *)
"invalid block type";
895 }
897 break;
901 if ((
hold & 0xffff) != ((
hold >> 16) ^ 0xffff)) {
902 strm->msg = (
char *)
"invalid stored block lengths";
904 break;
905 }
907 Tracev((stderr,
"inflate: stored length %u\n",
911 if (flush ==
Z_TREES)
goto inf_leave;
912
915
918 if (copy) {
920 if (copy > left)
copy = left;
921 if (copy == 0) goto inf_leave;
928 break;
929 }
930 Tracev((stderr,
"inflate: stored end\n"));
932 break;
941#ifndef PKZIP_BUG_WORKAROUND
942 if (state->
nlen > 286 || state->
ndist > 30) {
943 strm->msg = (
char *)
"too many length or distance symbols";
945 break;
946 }
947#endif
948 Tracev((stderr,
"inflate: table sizes ok\n"));
951
955 state->
lens[order[state->
have++]] = (
unsigned short)
BITS(3);
957 }
958 while (state->
have < 19)
959 state->
lens[order[state->
have++]] = 0;
965 if (ret) {
966 strm->msg = (
char *)
"invalid code lengths set";
968 break;
969 }
970 Tracev((stderr,
"inflate: code lengths ok\n"));
973
976 for (;;) {
978 if ((
unsigned)(here.
bits) <=
bits)
break;
980 }
984 }
985 else {
986 if (here.
val == 16) {
989 if (state->
have == 0) {
990 strm->msg = (
char *)
"invalid bit length repeat";
992 break;
993 }
997 }
998 else if (here.
val == 17) {
1001 len = 0;
1004 }
1005 else {
1008 len = 0;
1011 }
1013 strm->msg = (
char *)
"invalid bit length repeat";
1015 break;
1016 }
1017 while (copy--)
1018 state->
lens[state->
have++] = (
unsigned short)len;
1019 }
1020 }
1021
1022
1023 if (state->
mode ==
BAD)
break;
1024
1025
1026 if (state->
lens[256] == 0) {
1027 strm->msg = (
char *)
"invalid code -- missing end-of-block";
1029 break;
1030 }
1031
1032
1033
1034
1040 if (ret) {
1041 strm->msg = (
char *)
"invalid literal/lengths set";
1043 break;
1044 }
1049 if (ret) {
1050 strm->msg = (
char *)
"invalid distances set";
1052 break;
1053 }
1054 Tracev((stderr,
"inflate: codes ok\n"));
1056 if (flush ==
Z_TREES)
goto inf_leave;
1057
1060
1062 if (
have >= 6 && left >= 258) {
1068 break;
1069 }
1071 for (;;) {
1073 if ((
unsigned)(here.
bits) <=
bits)
break;
1075 }
1076 if (here.
op && (here.
op & 0xf0) == 0) {
1078 for (;;) {
1083 }
1086 }
1090 if ((
int)(here.
op) == 0) {
1092 "inflate: literal '%c'\n" :
1093 "inflate: literal 0x%02x\n", here.
val));
1095 break;
1096 }
1098 Tracevv((stderr,
"inflate: end of block\n"));
1101 break;
1102 }
1104 strm->msg = (
char *)
"invalid literal/length code";
1106 break;
1107 }
1108 state->
extra = (unsigned)(here.
op) & 15;
1110
1117 }
1121
1123 for (;;) {
1125 if ((
unsigned)(here.
bits) <=
bits)
break;
1127 }
1128 if ((here.
op & 0xf0) == 0) {
1130 for (;;) {
1135 }
1138 }
1142 strm->msg = (
char *)
"invalid distance code";
1144 break;
1145 }
1147 state->
extra = (
unsigned)(here.
op) & 15;
1149
1156 }
1157#ifdef INFLATE_STRICT
1159 strm->msg = (
char *)
"invalid distance too far back";
1161 break;
1162 }
1163#endif
1166
1168 if (left == 0) goto inf_leave;
1170 if (state->
offset > copy) {
1172 if (copy > state->
whave) {
1174 strm->msg = (
char *)
"invalid distance too far back";
1176 break;
1177 }
1178#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1179 Trace((stderr,
"inflate.c too far\n"));
1182 if (copy > left)
copy = left;
1185 do {
1186 *put++ = 0;
1187 } while (--copy);
1189 break;
1190#endif
1191 }
1192 if (copy > state->
wnext) {
1195 }
1196 else
1199 }
1200 else {
1201 from = put - state->
offset;
1203 }
1204 if (copy > left)
copy = left;
1207 do {
1208 *put++ = *from++;
1209 } while (--copy);
1211 break;
1213 if (left == 0) goto inf_leave;
1214 *put++ = (
unsigned char)(state->
length);
1215 left--;
1217 break;
1221 out -= left;
1222 strm->total_out += out;
1223 state->
total += out;
1224 if ((state->
wrap & 4) && out)
1227 out = left;
1228 if ((state->
wrap & 4) && (
1231#endif
1233 strm->msg = (
char *)
"incorrect data check";
1235 break;
1236 }
1238 Tracev((stderr,
"inflate: check matches trailer\n"));
1239 }
1240#ifdef GUNZIP
1242
1246 if ((state->
wrap & 4) &&
hold != (state->
total & 0xffffffff)) {
1247 strm->msg = (
char *)
"incorrect length check";
1249 break;
1250 }
1252 Tracev((stderr,
"inflate: length matches trailer\n"));
1253 }
1254#endif
1256
1259 goto inf_leave;
1262 goto inf_leave;
1266
1267 default:
1269 }
1270
1271
1272
1273
1274
1275
1276
1277 inf_leave:
1284 }
1285 in -=
strm->avail_in;
1286 out -=
strm->avail_out;
1287 strm->total_in += in;
1288 strm->total_out += out;
1289 state->
total += out;
1290 if ((state->
wrap & 4) && out)
1293 strm->data_type = (int)state->
bits + (state->
last ? 64 : 0) +
1296 if (((in == 0 && out == 0) || flush ==
Z_FINISH) && ret ==
Z_OK)
1298 return ret;
1299}
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)
int inflateStateCheck(z_streamp strm)
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)