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) {
172 windowBits = -windowBits;
175 wrap = (windowBits >> 4) + 5;
183 if (windowBits && (windowBits < 8 || windowBits > 15))
192 state->
wbits = (unsigned)windowBits;
206 stream_size != (
int)(
sizeof(
z_stream)))
210 if (
strm->zalloc == (alloc_func)0) {
215 strm->opaque = (voidpf)0;
218 if (
strm->zfree == (free_func)0)
227 Tracev((stderr,
"inflate: allocated\n"));
263 value &= (1L <<
bits) - 1;
264 state->
hold += (unsigned)value << state->
bits;
283 static int virgin = 1;
284 static code *lenfix, *distfix;
285 static code fixed[544];
294 while (sym < 144) state->
lens[sym++] = 8;
295 while (sym < 256) state->
lens[sym++] = 9;
296 while (sym < 280) state->
lens[sym++] = 7;
297 while (sym < 288) state->
lens[sym++] = 8;
305 while (sym < 32) state->
lens[sym++] = 5;
349 puts(
" /* inffixed.h -- table for decoding fixed codes");
350 puts(
" * Generated automatically by makefixed().");
353 puts(
" /* WARNING: this file should *not* be used by applications.");
354 puts(
" It is part of the implementation of this library and is");
355 puts(
" subject to change. Applications should only use zlib.h.");
359 printf(
" static const code lenfix[%u] = {", size);
362 if ((low % 7) == 0) printf(
"\n ");
363 printf(
"{%u,%u,%d}", (low & 127) == 99 ? 64 : state.
lencode[low].
op,
365 if (++low == size)
break;
370 printf(
"\n static const code distfix[%u] = {", size);
373 if ((low % 6) == 0) printf(
"\n ");
376 if (++low == size)
break;
409 state->
window = (
unsigned char FAR *)
411 sizeof(
unsigned char));
416 if (state->
wsize == 0) {
423 if (copy >= state->
wsize) {
430 if (dist > copy) dist = copy;
439 state->
wnext += dist;
451# define UPDATE_CHECK(check, buf, len) \
452 (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
454# define UPDATE_CHECK(check, buf, len) adler32(check, buf, len)
459# define CRC2(check, word) \
461 hbuf[0] = (unsigned char)(word); \
462 hbuf[1] = (unsigned char)((word) >> 8); \
463 check = crc32(check, hbuf, 2); \
466# define CRC4(check, word) \
468 hbuf[0] = (unsigned char)(word); \
469 hbuf[1] = (unsigned char)((word) >> 8); \
470 hbuf[2] = (unsigned char)((word) >> 16); \
471 hbuf[3] = (unsigned char)((word) >> 24); \
472 check = crc32(check, hbuf, 4); \
479 put = strm->next_out; \
480 left = strm->avail_out; \
481 next = strm->next_in; \
482 have = strm->avail_in; \
483 hold = state->hold; \
484 bits = state->bits; \
490 strm->next_out = put; \
491 strm->avail_out = left; \
492 strm->next_in = next; \
493 strm->avail_in = have; \
494 state->hold = hold; \
495 state->bits = bits; \
509 if (have == 0) goto inf_leave; \
511 hold += (unsigned long)(*next++) << bits; \
519 while (bits < (unsigned)(n)) \
525 ((unsigned)hold & ((1U << (n)) - 1))
531 bits -= (unsigned)(n); \
628 z_const
unsigned char FAR *
next;
629 unsigned char FAR *put;
635 unsigned char FAR *from;
641 unsigned char hbuf[4];
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};
657 switch (state->
mode) {
659 if (state->
wrap == 0) {
665 if ((state->
wrap & 2) &&
hold == 0x8b1f) {
666 if (state->
wbits == 0)
675 state->
head->done = -1;
676 if (!(state->
wrap & 1) ||
680 ((
BITS(8) << 8) + (
hold >> 8)) % 31) {
681 strm->msg = (
char *)
"incorrect header check";
686 strm->msg = (
char *)
"unknown compression method";
692 if (state->
wbits == 0)
694 if (len > 15 || len > state->
wbits) {
695 strm->msg = (
char *)
"invalid window size";
699 state->
dmax = 1U << len;
701 Tracev((stderr,
"inflate: zlib header ok\n"));
711 strm->msg = (
char *)
"unknown compression method";
715 if (state->
flags & 0xe000) {
716 strm->msg = (
char *)
"unknown header flags set";
721 state->
head->text = (int)((
hold >> 8) & 1);
722 if ((state->
flags & 0x0200) && (state->
wrap & 4))
731 if ((state->
flags & 0x0200) && (state->
wrap & 4))
739 state->
head->xflags = (int)(
hold & 0xff);
742 if ((state->
flags & 0x0200) && (state->
wrap & 4))
748 if (state->
flags & 0x0400) {
752 state->
head->extra_len = (unsigned)
hold;
753 if ((state->
flags & 0x0200) && (state->
wrap & 4))
762 if (state->
flags & 0x0400) {
770 len + copy > state->
head->extra_max ?
771 state->
head->extra_max - len : copy);
773 if ((state->
flags & 0x0200) && (state->
wrap & 4))
779 if (state->
length)
goto inf_leave;
785 if (state->
flags & 0x0800) {
786 if (
have == 0)
goto inf_leave;
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;
807 if (state->
flags & 0x1000) {
808 if (
have == 0)
goto inf_leave;
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;
828 if (state->
flags & 0x0200) {
831 strm->msg = (
char *)
"header crc mismatch";
838 state->
head->hcrc = (int)((state->
flags >> 9) & 1);
839 state->
head->done = 1;
873 Tracev((stderr,
"inflate: stored block%s\n",
874 state->
last ?
" (last)" :
""));
879 Tracev((stderr,
"inflate: fixed codes block%s\n",
880 state->
last ?
" (last)" :
""));
888 Tracev((stderr,
"inflate: dynamic codes block%s\n",
889 state->
last ?
" (last)" :
""));
893 strm->msg = (
char *)
"invalid block type";
901 if ((
hold & 0xffff) != ((
hold >> 16) ^ 0xffff)) {
902 strm->msg = (
char *)
"invalid stored block lengths";
907 Tracev((stderr,
"inflate: stored length %u\n",
911 if (flush ==
Z_TREES)
goto inf_leave;
920 if (copy > left) copy = left;
921 if (copy == 0)
goto inf_leave;
930 Tracev((stderr,
"inflate: stored end\n"));
941#ifndef PKZIP_BUG_WORKAROUND
942 if (state->
nlen > 286 || state->
ndist > 30) {
943 strm->msg = (
char *)
"too many length or distance symbols";
948 Tracev((stderr,
"inflate: table sizes ok\n"));
955 state->
lens[order[state->
have++]] = (
unsigned short)
BITS(3);
958 while (state->
have < 19)
959 state->
lens[order[state->
have++]] = 0;
966 strm->msg = (
char *)
"invalid code lengths set";
970 Tracev((stderr,
"inflate: code lengths ok\n"));
978 if ((
unsigned)(here.
bits) <=
bits)
break;
986 if (here.
val == 16) {
989 if (state->
have == 0) {
990 strm->msg = (
char *)
"invalid bit length repeat";
998 else if (here.
val == 17) {
1009 copy = 11 +
BITS(7);
1013 strm->msg = (
char *)
"invalid bit length repeat";
1018 state->
lens[state->
have++] = (
unsigned short)len;
1023 if (state->
mode ==
BAD)
break;
1026 if (state->
lens[256] == 0) {
1027 strm->msg = (
char *)
"invalid code -- missing end-of-block";
1041 strm->msg = (
char *)
"invalid literal/lengths set";
1050 strm->msg = (
char *)
"invalid distances set";
1054 Tracev((stderr,
"inflate: codes ok\n"));
1056 if (flush ==
Z_TREES)
goto inf_leave;
1062 if (
have >= 6 && left >= 258) {
1073 if ((
unsigned)(here.
bits) <=
bits)
break;
1076 if (here.
op && (here.
op & 0xf0) == 0) {
1090 if ((
int)(here.
op) == 0) {
1092 "inflate: literal '%c'\n" :
1093 "inflate: literal 0x%02x\n", here.
val));
1098 Tracevv((stderr,
"inflate: end of block\n"));
1104 strm->msg = (
char *)
"invalid literal/length code";
1108 state->
extra = (unsigned)(here.
op) & 15;
1125 if ((
unsigned)(here.
bits) <=
bits)
break;
1128 if ((here.
op & 0xf0) == 0) {
1142 strm->msg = (
char *)
"invalid distance code";
1147 state->
extra = (
unsigned)(here.
op) & 15;
1157#ifdef INFLATE_STRICT
1159 strm->msg = (
char *)
"invalid distance too far back";
1168 if (left == 0)
goto inf_leave;
1170 if (state->
offset > copy) {
1171 copy = state->
offset - copy;
1172 if (copy > state->
whave) {
1174 strm->msg = (
char *)
"invalid distance too far back";
1178#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1179 Trace((stderr,
"inflate.c too far\n"));
1180 copy -= state->
whave;
1182 if (copy > left) copy = left;
1192 if (copy > state->
wnext) {
1193 copy -= state->
wnext;
1201 from = put - state->
offset;
1204 if (copy > left) copy = left;
1213 if (left == 0)
goto inf_leave;
1214 *put++ = (
unsigned char)(state->
length);
1222 strm->total_out += out;
1223 state->
total += out;
1224 if ((state->
wrap & 4) && out)
1228 if ((state->
wrap & 4) && (
1233 strm->msg = (
char *)
"incorrect data check";
1238 Tracev((stderr,
"inflate: check matches trailer\n"));
1246 if ((state->
wrap & 4) &&
hold != (state->
total & 0xffffffff)) {
1247 strm->msg = (
char *)
"incorrect length check";
1252 Tracev((stderr,
"inflate: length matches trailer\n"));
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)
1311 Tracev((stderr,
"inflate: end\n"));
1333 if (dictLength !=
Z_NULL)
1334 *dictLength = state->
whave;
1340const Bytef *dictionary;
1344 unsigned long dictid;
1356 dictid =
adler32(dictid, dictionary, dictLength);
1357 if (dictid != state->
check)
1369 Tracev((stderr,
"inflate: dictionary set\n"));
1403const unsigned char FAR *buf;
1411 while (
next < len && got < 4) {
1412 if ((
int)(buf[
next]) == (got < 2 ? 0 : 0xff))
1429 unsigned long in, out;
1430 unsigned char buf[4];
1444 while (state->
bits >= 8) {
1445 buf[len++] = (
unsigned char)(state->
hold);
1455 strm->avail_in -= len;
1456 strm->next_in += len;
1457 strm->total_in += len;
1461 if (state->
flags == -1)
1466 in =
strm->total_in; out =
strm->total_out;
1468 strm->total_in = in;
strm->total_out = out;
1498 unsigned char FAR *
window;
1512 window = (
unsigned char FAR *)
1513 ZALLOC(source, 1U << state->
wbits,
sizeof(
unsigned char));
1515 ZFREE(source, copy);
1526 copy->lencode = copy->codes + (state->
lencode - state->
codes);
1527 copy->distcode = copy->codes + (state->
distcode - state->
codes);
1529 copy->next = copy->codes + (state->
next - state->
codes);
1547#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1548 state->
sane = !subvert;
1580 return (
long)(((
unsigned long)((
long)state->
back)) << 16) +
1591 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)
void fixedtables(struct inflate_state FAR *state)
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)
int ZEXPORT inflateSyncPoint(z_streamp strm)
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 inflateStateCheck(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)
int updatewindow(z_streamp strm, const Bytef *end, unsigned copy)
int ZEXPORT inflateReset(z_streamp strm)
unsigned syncsearch(unsigned FAR *have, const unsigned char FAR *buf, unsigned len)
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
voidpf alloc_func OF((voidpf opaque, uInt items, uInt size))
void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr)
voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size)
void ZLIB_INTERNAL zmemcpy(Bytef *dest, const Bytef *source, uInt len)
#define ZALLOC(strm, items, size)
#define ZFREE(strm, addr)