100 void makefixed
OF((
void));
110 strm->zalloc == (alloc_func)0 ||
strm->zfree == (free_func)0)
133 state->
dmax = 32768U;
140 Tracev((stderr,
"inflate: reset\n"));
169 if (windowBits < 0) {
171 windowBits = -windowBits;
174 wrap = (windowBits >> 4) + 5;
182 if (windowBits && (windowBits < 8 || windowBits > 15))
191 state->
wbits = (unsigned)windowBits;
205 stream_size != (
int)(
sizeof(
z_stream)))
209 if (
strm->zalloc == (alloc_func)0) {
214 strm->opaque = (voidpf)0;
217 if (
strm->zfree == (free_func)0)
226 Tracev((stderr,
"inflate: allocated\n"));
262 value &= (1L <<
bits) - 1;
263 state->
hold += (unsigned)value << state->
bits;
282 static int virgin = 1;
283 static code *lenfix, *distfix;
284 static code fixed[544];
293 while (sym < 144) state->
lens[sym++] = 8;
294 while (sym < 256) state->
lens[sym++] = 9;
295 while (sym < 280) state->
lens[sym++] = 7;
296 while (sym < 288) state->
lens[sym++] = 8;
304 while (sym < 32) state->
lens[sym++] = 5;
348 puts(
" /* inffixed.h -- table for decoding fixed codes");
349 puts(
" * Generated automatically by makefixed().");
352 puts(
" /* WARNING: this file should *not* be used by applications.");
353 puts(
" It is part of the implementation of this library and is");
354 puts(
" subject to change. Applications should only use zlib.h.");
358 printf(
" static const code lenfix[%u] = {", size);
361 if ((low % 7) == 0) printf(
"\n ");
362 printf(
"{%u,%u,%d}", (low & 127) == 99 ? 64 : state.
lencode[low].
op,
364 if (++low == size)
break;
369 printf(
"\n static const code distfix[%u] = {", size);
372 if ((low % 6) == 0) printf(
"\n ");
375 if (++low == size)
break;
408 state->
window = (
unsigned char FAR *)
410 sizeof(
unsigned char));
415 if (state->
wsize == 0) {
422 if (copy >= state->
wsize) {
429 if (dist > copy) dist = copy;
438 state->
wnext += dist;
450# define UPDATE(check, buf, len) \
451 (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
453# define UPDATE(check, buf, len) adler32(check, buf, len)
458# define CRC2(check, word) \
460 hbuf[0] = (unsigned char)(word); \
461 hbuf[1] = (unsigned char)((word) >> 8); \
462 check = crc32(check, hbuf, 2); \
465# define CRC4(check, word) \
467 hbuf[0] = (unsigned char)(word); \
468 hbuf[1] = (unsigned char)((word) >> 8); \
469 hbuf[2] = (unsigned char)((word) >> 16); \
470 hbuf[3] = (unsigned char)((word) >> 24); \
471 check = crc32(check, hbuf, 4); \
478 put = strm->next_out; \
479 left = strm->avail_out; \
480 next = strm->next_in; \
481 have = strm->avail_in; \
482 hold = state->hold; \
483 bits = state->bits; \
489 strm->next_out = put; \
490 strm->avail_out = left; \
491 strm->next_in = next; \
492 strm->avail_in = have; \
493 state->hold = hold; \
494 state->bits = bits; \
508 if (have == 0) goto inf_leave; \
510 hold += (unsigned long)(*next++) << bits; \
518 while (bits < (unsigned)(n)) \
524 ((unsigned)hold & ((1U << (n)) - 1))
530 bits -= (unsigned)(n); \
627 z_const
unsigned char FAR *
next;
628 unsigned char FAR *put;
634 unsigned char FAR *from;
640 unsigned char hbuf[4];
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};
656 switch (state->
mode) {
658 if (state->
wrap == 0) {
664 if ((state->
wrap & 2) &&
hold == 0x8b1f) {
665 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;
700 Tracev((stderr,
"inflate: zlib header ok\n"));
710 strm->msg = (
char *)
"unknown compression method";
714 if (state->
flags & 0xe000) {
715 strm->msg = (
char *)
"unknown header flags set";
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);
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))
757 if (state->
flags & 0x0400) {
765 len + copy > state->
head->extra_max ?
766 state->
head->extra_max - len : copy);
768 if ((state->
flags & 0x0200) && (state->
wrap & 4))
774 if (state->
length)
goto inf_leave;
779 if (state->
flags & 0x0800) {
780 if (
have == 0)
goto inf_leave;
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;
800 if (state->
flags & 0x1000) {
801 if (
have == 0)
goto inf_leave;
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;
820 if (state->
flags & 0x0200) {
823 strm->msg = (
char *)
"header crc mismatch";
830 state->
head->hcrc = (int)((state->
flags >> 9) & 1);
831 state->
head->done = 1;
862 Tracev((stderr,
"inflate: stored block%s\n",
863 state->
last ?
" (last)" :
""));
868 Tracev((stderr,
"inflate: fixed codes block%s\n",
869 state->
last ?
" (last)" :
""));
877 Tracev((stderr,
"inflate: dynamic codes block%s\n",
878 state->
last ?
" (last)" :
""));
882 strm->msg = (
char *)
"invalid block type";
890 if ((
hold & 0xffff) != ((
hold >> 16) ^ 0xffff)) {
891 strm->msg = (
char *)
"invalid stored block lengths";
896 Tracev((stderr,
"inflate: stored length %u\n",
900 if (flush ==
Z_TREES)
goto inf_leave;
907 if (copy > left) copy = left;
908 if (copy == 0)
goto inf_leave;
917 Tracev((stderr,
"inflate: stored end\n"));
928#ifndef PKZIP_BUG_WORKAROUND
929 if (state->
nlen > 286 || state->
ndist > 30) {
930 strm->msg = (
char *)
"too many length or distance symbols";
935 Tracev((stderr,
"inflate: table sizes ok\n"));
941 state->
lens[order[state->
have++]] = (
unsigned short)
BITS(3);
944 while (state->
have < 19)
945 state->
lens[order[state->
have++]] = 0;
952 strm->msg = (
char *)
"invalid code lengths set";
956 Tracev((stderr,
"inflate: code lengths ok\n"));
963 if ((
unsigned)(here.
bits) <=
bits)
break;
971 if (here.
val == 16) {
974 if (state->
have == 0) {
975 strm->msg = (
char *)
"invalid bit length repeat";
983 else if (here.
val == 17) {
998 strm->msg = (
char *)
"invalid bit length repeat";
1003 state->
lens[state->
have++] = (
unsigned short)len;
1008 if (state->
mode ==
BAD)
break;
1011 if (state->
lens[256] == 0) {
1012 strm->msg = (
char *)
"invalid code -- missing end-of-block";
1026 strm->msg = (
char *)
"invalid literal/lengths set";
1035 strm->msg = (
char *)
"invalid distances set";
1039 Tracev((stderr,
"inflate: codes ok\n"));
1041 if (flush ==
Z_TREES)
goto inf_leave;
1045 if (
have >= 6 && left >= 258) {
1056 if ((
unsigned)(here.
bits) <=
bits)
break;
1059 if (here.
op && (here.
op & 0xf0) == 0) {
1073 if ((
int)(here.
op) == 0) {
1075 "inflate: literal '%c'\n" :
1076 "inflate: literal 0x%02x\n", here.
val));
1081 Tracevv((stderr,
"inflate: end of block\n"));
1087 strm->msg = (
char *)
"invalid literal/length code";
1091 state->
extra = (unsigned)(here.
op) & 15;
1106 if ((
unsigned)(here.
bits) <=
bits)
break;
1109 if ((here.
op & 0xf0) == 0) {
1123 strm->msg = (
char *)
"invalid distance code";
1128 state->
extra = (
unsigned)(here.
op) & 15;
1137#ifdef INFLATE_STRICT
1139 strm->msg = (
char *)
"invalid distance too far back";
1147 if (left == 0)
goto inf_leave;
1149 if (state->
offset > copy) {
1150 copy = state->
offset - copy;
1151 if (copy > state->
whave) {
1153 strm->msg = (
char *)
"invalid distance too far back";
1157#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1158 Trace((stderr,
"inflate.c too far\n"));
1159 copy -= state->
whave;
1161 if (copy > left) copy = left;
1171 if (copy > state->
wnext) {
1172 copy -= state->
wnext;
1180 from = put - state->
offset;
1183 if (copy > left) copy = left;
1192 if (left == 0)
goto inf_leave;
1193 *put++ = (
unsigned char)(state->
length);
1201 strm->total_out += out;
1202 state->
total += out;
1203 if ((state->
wrap & 4) && out)
1207 if ((state->
wrap & 4) && (
1212 strm->msg = (
char *)
"incorrect data check";
1217 Tracev((stderr,
"inflate: check matches trailer\n"));
1224 if (
hold != (state->
total & 0xffffffffUL)) {
1225 strm->msg = (
char *)
"incorrect length check";
1230 Tracev((stderr,
"inflate: length matches trailer\n"));
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)
1287 Tracev((stderr,
"inflate: end\n"));
1309 if (dictLength !=
Z_NULL)
1310 *dictLength = state->
whave;
1316const Bytef *dictionary;
1320 unsigned long dictid;
1332 dictid =
adler32(dictid, dictionary, dictLength);
1333 if (dictid != state->
check)
1345 Tracev((stderr,
"inflate: dictionary set\n"));
1379const unsigned char FAR *buf;
1387 while (
next < len && got < 4) {
1388 if ((
int)(buf[
next]) == (got < 2 ? 0 : 0xff))
1404 unsigned long in, out;
1405 unsigned char buf[4];
1419 while (state->
bits >= 8) {
1420 buf[len++] = (
unsigned char)(state->
hold);
1430 strm->avail_in -= len;
1431 strm->next_in += len;
1432 strm->total_in += len;
1436 in =
strm->total_in; out =
strm->total_out;
1438 strm->total_in = in;
strm->total_out = out;
1467 unsigned char FAR *
window;
1481 window = (
unsigned char FAR *)
1482 ZALLOC(source, 1U << state->
wbits,
sizeof(
unsigned char));
1484 ZFREE(source, copy);
1495 copy->lencode = copy->codes + (state->
lencode - state->
codes);
1496 copy->distcode = copy->codes + (state->
distcode - state->
codes);
1498 copy->next = copy->codes + (state->
next - state->
codes);
1516#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1517 state->
sane = !subvert;
1549 return (
long)(((
unsigned long)((
long)state->
back)) << 16) +
1560 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)
#define UPDATE(check, buf, 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 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)
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)