100 void makefixed
OF((
void));
110 strm->zalloc == (alloc_func)0 ||
strm->zfree == (free_func)0)
134 state->
dmax = 32768U;
141 Tracev((stderr,
"inflate: reset\n"));
170 if (windowBits < 0) {
171 if (windowBits < -15)
174 windowBits = -windowBits;
177 wrap = (windowBits >> 4) + 5;
185 if (windowBits && (windowBits < 8 || windowBits > 15))
194 state->
wbits = (unsigned)windowBits;
208 stream_size != (
int)(
sizeof(
z_stream)))
212 if (
strm->zalloc == (alloc_func)0) {
220 if (
strm->zfree == (free_func)0)
229 Tracev((stderr,
"inflate: allocated\n"));
285 static int virgin = 1;
286 static code *lenfix, *distfix;
287 static code fixed[544];
296 while (sym < 144) state->
lens[sym++] = 8;
297 while (sym < 256) state->
lens[sym++] = 9;
298 while (sym < 280) state->
lens[sym++] = 7;
299 while (sym < 288) state->
lens[sym++] = 8;
307 while (sym < 32) state->
lens[sym++] = 5;
351 puts(
" /* inffixed.h -- table for decoding fixed codes");
352 puts(
" * Generated automatically by makefixed().");
355 puts(
" /* WARNING: this file should *not* be used by applications.");
356 puts(
" It is part of the implementation of this library and is");
357 puts(
" subject to change. Applications should only use zlib.h.");
361 printf(
" static const code lenfix[%u] = {",
size);
364 if ((low % 7) == 0) printf(
"\n ");
365 printf(
"{%u,%u,%d}", (low & 127) == 99 ? 64 : state.
lencode[low].
op,
367 if (++low ==
size)
break;
372 printf(
"\n static const code distfix[%u] = {",
size);
375 if ((low % 6) == 0) printf(
"\n ");
378 if (++low ==
size)
break;
413 sizeof(
unsigned char));
418 if (state->
wsize == 0) {
425 if (copy >= state->
wsize) {
432 if (dist > copy) dist = copy;
441 state->
wnext += dist;
453# define UPDATE_CHECK(check, buf, len) \
454 (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
456# define UPDATE_CHECK(check, buf, len) adler32(check, buf, len)
461# define CRC2(check, word) \
463 hbuf[0] = (unsigned char)(word); \
464 hbuf[1] = (unsigned char)((word) >> 8); \
465 check = crc32(check, hbuf, 2); \
468# define CRC4(check, word) \
470 hbuf[0] = (unsigned char)(word); \
471 hbuf[1] = (unsigned char)((word) >> 8); \
472 hbuf[2] = (unsigned char)((word) >> 16); \
473 hbuf[3] = (unsigned char)((word) >> 24); \
474 check = crc32(check, hbuf, 4); \
481 put = strm->next_out; \
482 left = strm->avail_out; \
483 next = strm->next_in; \
484 have = strm->avail_in; \
485 hold = state->hold; \
486 bits = state->bits; \
492 strm->next_out = put; \
493 strm->avail_out = left; \
494 strm->next_in = next; \
495 strm->avail_in = have; \
496 state->hold = hold; \
497 state->bits = bits; \
511 if (have == 0) goto inf_leave; \
513 hold += (unsigned long)(*next++) << bits; \
521 while (bits < (unsigned)(n)) \
527 ((unsigned)hold & ((1U << (n)) - 1))
533 bits -= (unsigned)(n); \
631 unsigned char FAR *put;
637 unsigned char FAR *from;
642#ifdef OC_INFLATE_VERIFY_DATA
644 unsigned char hbuf[4];
647 static const unsigned short order[19] =
648 {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
661 switch (state->
mode) {
663 if (state->
wrap == 0) {
669 if ((state->
wrap & 2) &&
hold == 0x8b1f) {
670 if (state->
wbits == 0)
672#ifdef OC_INFLATE_VERIFY_DATA
681 state->
head->done = -1;
682 if (!(state->
wrap & 1) ||
686 ((
BITS(8) << 8) + (
hold >> 8)) % 31) {
687 strm->msg = (
char *)
"incorrect header check";
692 strm->msg = (
char *)
"unknown compression method";
698 if (state->
wbits == 0)
700 if (len > 15 || len > state->
wbits) {
701 strm->msg = (
char *)
"invalid window size";
705 state->
dmax = 1U << len;
707 Tracev((stderr,
"inflate: zlib header ok\n"));
708#ifdef OC_INFLATE_VERIFY_DATA
719 strm->msg = (
char *)
"unknown compression method";
723 if (state->
flags & 0xe000) {
724 strm->msg = (
char *)
"unknown header flags set";
729 state->
head->text = (int)((
hold >> 8) & 1);
730#ifdef OC_INFLATE_VERIFY_DATA
731 if ((state->
flags & 0x0200) && (state->
wrap & 4))
741#ifdef OC_INFLATE_VERIFY_DATA
742 if ((state->
flags & 0x0200) && (state->
wrap & 4))
751 state->
head->xflags = (int)(
hold & 0xff);
754#ifdef OC_INFLATE_VERIFY_DATA
755 if ((state->
flags & 0x0200) && (state->
wrap & 4))
762 if (state->
flags & 0x0400) {
766 state->
head->extra_len = (unsigned)
hold;
767#ifdef OC_INFLATE_VERIFY_DATA
768 if ((state->
flags & 0x0200) && (state->
wrap & 4))
778 if (state->
flags & 0x0400) {
784 (len = state->
head->extra_len - state->
length) <
785 state->
head->extra_max) {
787 len + copy > state->
head->extra_max ?
788 state->
head->extra_max - len : copy);
790#ifdef OC_INFLATE_VERIFY_DATA
791 if ((state->
flags & 0x0200) && (state->
wrap & 4))
798 if (state->
length)
goto inf_leave;
804 if (state->
flags & 0x0800) {
805 if (
have == 0)
goto inf_leave;
808 len = (unsigned)(
next[copy++]);
813 }
while (len && copy <
have);
814#ifdef OC_INFLATE_VERIFY_DATA
815 if ((state->
flags & 0x0200) && (state->
wrap & 4))
820 if (len)
goto inf_leave;
828 if (state->
flags & 0x1000) {
829 if (
have == 0)
goto inf_leave;
832 len = (unsigned)(
next[copy++]);
837 }
while (len && copy <
have);
838#ifdef OC_INFLATE_VERIFY_DATA
839 if ((state->
flags & 0x0200) && (state->
wrap & 4))
844 if (len)
goto inf_leave;
851 if (state->
flags & 0x0200) {
853#ifdef OC_INFLATE_VERIFY_DATA
855 strm->msg = (
char *)
"header crc mismatch";
863 state->
head->hcrc = (int)((state->
flags >> 9) & 1);
864 state->
head->done = 1;
866#ifdef OC_INFLATE_VERIFY_DATA
874#ifdef OC_INFLATE_VERIFY_DATA
885#ifdef OC_INFLATE_VERIFY_DATA
904 Tracev((stderr,
"inflate: stored block%s\n",
905 state->
last ?
" (last)" :
""));
910 Tracev((stderr,
"inflate: fixed codes block%s\n",
911 state->
last ?
" (last)" :
""));
919 Tracev((stderr,
"inflate: dynamic codes block%s\n",
920 state->
last ?
" (last)" :
""));
924 strm->msg = (
char *)
"invalid block type";
932 if ((
hold & 0xffff) != ((
hold >> 16) ^ 0xffff)) {
933 strm->msg = (
char *)
"invalid stored block lengths";
938 Tracev((stderr,
"inflate: stored length %u\n",
942 if (flush ==
Z_TREES)
goto inf_leave;
951 if (copy > left) copy = left;
952 if (copy == 0)
goto inf_leave;
961 Tracev((stderr,
"inflate: stored end\n"));
972#ifndef PKZIP_BUG_WORKAROUND
973 if (state->
nlen > 286 || state->
ndist > 30) {
974 strm->msg = (
char *)
"too many length or distance symbols";
979 Tracev((stderr,
"inflate: table sizes ok\n"));
986 state->
lens[order[state->
have++]] = (
unsigned short)
BITS(3);
989 while (state->
have < 19)
990 state->
lens[order[state->
have++]] = 0;
997 strm->msg = (
char *)
"invalid code lengths set";
1001 Tracev((stderr,
"inflate: code lengths ok\n"));
1009 if ((
unsigned)(here.
bits) <=
bits)
break;
1012 if (here.
val < 16) {
1017 if (here.
val == 16) {
1020 if (state->
have == 0) {
1021 strm->msg = (
char *)
"invalid bit length repeat";
1025 len = state->
lens[state->
have - 1];
1029 else if (here.
val == 17) {
1040 copy = 11 +
BITS(7);
1044 strm->msg = (
char *)
"invalid bit length repeat";
1049 state->
lens[state->
have++] = (
unsigned short)len;
1054 if (state->
mode ==
BAD)
break;
1057 if (state->
lens[256] == 0) {
1058 strm->msg = (
char *)
"invalid code -- missing end-of-block";
1072 strm->msg = (
char *)
"invalid literal/lengths set";
1081 strm->msg = (
char *)
"invalid distances set";
1085 Tracev((stderr,
"inflate: codes ok\n"));
1087 if (flush ==
Z_TREES)
goto inf_leave;
1093 if (
have >= 6 && left >= 258) {
1104 if ((
unsigned)(here.
bits) <=
bits)
break;
1107 if (here.
op && (here.
op & 0xf0) == 0) {
1121 if ((
int)(here.
op) == 0) {
1123 "inflate: literal '%c'\n" :
1124 "inflate: literal 0x%02x\n", here.
val));
1129 Tracevv((stderr,
"inflate: end of block\n"));
1135 strm->msg = (
char *)
"invalid literal/length code";
1139 state->
extra = (unsigned)(here.
op) & 15;
1156 if ((
unsigned)(here.
bits) <=
bits)
break;
1159 if ((here.
op & 0xf0) == 0) {
1173 strm->msg = (
char *)
"invalid distance code";
1178 state->
extra = (unsigned)(here.
op) & 15;
1188#ifdef INFLATE_STRICT
1190 strm->msg = (
char *)
"invalid distance too far back";
1199 if (left == 0)
goto inf_leave;
1201 if (state->
offset > copy) {
1202 copy = state->
offset - copy;
1203 if (copy > state->
whave) {
1205 strm->msg = (
char *)
"invalid distance too far back";
1209#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1210 Trace((stderr,
"inflate.c too far\n"));
1211 copy -= state->
whave;
1213 if (copy > left) copy = left;
1223 if (copy > state->
wnext) {
1224 copy -= state->
wnext;
1232 from = put - state->
offset;
1235 if (copy > left) copy = left;
1244 if (left == 0)
goto inf_leave;
1245 *put++ = (
unsigned char)(state->
length);
1253 strm->total_out += out;
1254 state->
total += out;
1255#ifdef OC_INFLATE_VERIFY_DATA
1256 if ((state->
wrap & 4) && out)
1261#ifdef OC_INFLATE_VERIFY_DATA
1262 if ((state->
wrap & 4) && (
1267 strm->msg = (
char *)
"incorrect data check";
1273 Tracev((stderr,
"inflate: check matches trailer\n"));
1281 if ((state->
wrap & 4) &&
hold != (state->
total & 0xffffffff)) {
1282 strm->msg = (
char *)
"incorrect length check";
1287 Tracev((stderr,
"inflate: length matches trailer\n"));
1320 in -=
strm->avail_in;
1321 out -=
strm->avail_out;
1322 strm->total_in += in;
1323 strm->total_out += out;
1324 state->
total += out;
1325#ifdef OC_INFLATE_VERIFY_DATA
1326 if ((state->
wrap & 4) && out)
1330 strm->data_type = (int)state->
bits + (state->
last ? 64 : 0) +
1333 if (((in == 0 && out == 0) || flush ==
Z_FINISH) && ret ==
Z_OK)
1348 Tracev((stderr,
"inflate: end\n"));
1370 if (dictLength !=
Z_NULL)
1371 *dictLength = state->
whave;
1377const Bytef *dictionary;
1381#ifdef OC_INFLATE_VERIFY_DATA
1382 unsigned long dictid;
1393#ifdef OC_INFLATE_VERIFY_DATA
1396 dictid =
adler32(dictid, dictionary, dictLength);
1397 if (dictid != state->
check)
1410 Tracev((stderr,
"inflate: dictionary set\n"));
1444const unsigned char FAR *buf;
1452 while (
next < len && got < 4) {
1453 if ((
int)(buf[
next]) == (got < 2 ? 0 : 0xff))
1470 unsigned long in, out;
1471 unsigned char buf[4];
1485 while (state->
bits >= 8) {
1486 buf[len++] = (
unsigned char)(state->
hold);
1496 strm->avail_in -= len;
1497 strm->next_in += len;
1498 strm->total_in += len;
1502 if (state->
flags == -1)
1507 in =
strm->total_in; out =
strm->total_out;
1509 strm->total_in = in;
strm->total_out = out;
1554 ZALLOC(source, 1U << state->
wbits,
sizeof(
unsigned char));
1556 ZFREE(source, copy);
1588#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1589 state->
sane = !subvert;
1621 return (
long)(((
unsigned long)((long)state->
back)) << 16) +
1632 return (
unsigned long)(state->
next - state->
codes);
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)
unsigned long ZEXPORT inflateCodesUsed(z_streamp strm)
int ZEXPORT inflateSetDictionary(z_streamp strm, const Bytef *dictionary, uInt dictLength)
long ZEXPORT inflateMark(z_streamp strm)
int ZEXPORT inflateGetDictionary(z_streamp strm, Bytef *dictionary, uInt *dictLength)
local int inflateStateCheck(z_streamp strm)
local void fixedtables(struct inflate_state FAR *state)
int ZEXPORT inflateSyncPoint(z_streamp strm)
local unsigned syncsearch(unsigned FAR *have, const unsigned char FAR *buf, unsigned len)
int ZEXPORT inflatePrime(z_streamp strm, int bits, int value)
int ZEXPORT inflateGetHeader(z_streamp strm, gz_headerp head)
int ZEXPORT inflateUndermine(z_streamp strm, int subvert)
int ZEXPORT inflateSync(z_streamp strm)
int ZEXPORT inflateResetKeep(z_streamp strm)
int ZEXPORT inflate(z_streamp strm, int flush)
int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
local int updatewindow(z_streamp strm, const Bytef *end, unsigned copy)
int ZEXPORT inflateReset(z_streamp strm)
int ZEXPORT inflateInit_(z_streamp strm, const char *version, int stream_size)
int ZEXPORT inflateEnd(z_streamp strm)
int ZEXPORT inflateCopy(z_streamp dest, z_streamp source)
#define UPDATE_CHECK(check, buf, len)
int ZEXPORT inflateValidate(z_streamp strm, int check)
int ZEXPORT inflateReset2(z_streamp strm, int windowBits)
int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, unsigned codes, code FAR *FAR *table, unsigned FAR *bits, unsigned short FAR *work)
code const FAR * distcode
unsigned char FAR * window
gz_header FAR * gz_headerp
void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr)
voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size)
#define ZALLOC(strm, items, size)
#define ZFREE(strm, addr)
#define zmemcpy(Dst, Src, Size)