31unsigned char FAR *window;
38 stream_size != (
int)(
sizeof(
z_stream)))
41 windowBits < 8 || windowBits > 15)
44 if (
strm->zalloc == (alloc_func)0) {
49 strm->opaque = (voidpf)0;
52 if (
strm->zfree == (free_func)0)
61 Tracev((stderr,
"inflate: allocated\n"));
64 state->
wbits = (uInt)windowBits;
65 state->
wsize = 1U << windowBits;
86 static int virgin = 1;
87 static code *lenfix, *distfix;
88 static code fixed[544];
97 while (sym < 144) state->
lens[sym++] = 8;
98 while (sym < 256) state->
lens[sym++] = 9;
99 while (sym < 280) state->
lens[sym++] = 7;
100 while (sym < 288) state->
lens[sym++] = 8;
108 while (sym < 32) state->
lens[sym++] = 5;
130 put = strm->next_out; \
131 left = strm->avail_out; \
132 next = strm->next_in; \
133 have = strm->avail_in; \
134 hold = state->hold; \
135 bits = state->bits; \
141 strm->next_out = put; \
142 strm->avail_out = left; \
143 strm->next_in = next; \
144 strm->avail_in = have; \
145 state->hold = hold; \
146 state->bits = bits; \
161 have = in(in_desc, &next); \
176 hold += (unsigned long)(*next++) << bits; \
185 while (bits < (unsigned)(n)) \
191 ((unsigned)hold & ((1U << (n)) - 1))
197 bits -= (unsigned)(n); \
213 put = state->window; \
214 left = state->wsize; \
215 state->whave = left; \
216 if (out(out_desc, put, left)) { \
258 z_const
unsigned char FAR *
next;
259 unsigned char FAR *put;
264 unsigned char FAR *from;
269 static const unsigned short order[19] =
270 {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
291 switch (state->
mode) {
304 Tracev((stderr,
"inflate: stored block%s\n",
305 state->
last ?
" (last)" :
""));
310 Tracev((stderr,
"inflate: fixed codes block%s\n",
311 state->
last ?
" (last)" :
""));
315 Tracev((stderr,
"inflate: dynamic codes block%s\n",
316 state->
last ?
" (last)" :
""));
320 strm->msg = (
char *)
"invalid block type";
330 if ((
hold & 0xffff) != ((
hold >> 16) ^ 0xffff)) {
331 strm->msg = (
char *)
"invalid stored block lengths";
336 Tracev((stderr,
"inflate: stored length %u\n",
341 while (state->
length != 0) {
346 if (copy > left) copy = left;
354 Tracev((stderr,
"inflate: stored end\n"));
367#ifndef PKZIP_BUG_WORKAROUND
368 if (state->
nlen > 286 || state->
ndist > 30) {
369 strm->msg = (
char *)
"too many length or distance symbols";
374 Tracev((stderr,
"inflate: table sizes ok\n"));
380 state->
lens[order[state->
have++]] = (
unsigned short)
BITS(3);
383 while (state->
have < 19)
384 state->
lens[order[state->
have++]] = 0;
391 strm->msg = (
char *)
"invalid code lengths set";
395 Tracev((stderr,
"inflate: code lengths ok\n"));
402 if ((
unsigned)(here.
bits) <=
bits)
break;
410 if (here.
val == 16) {
413 if (state->
have == 0) {
414 strm->msg = (
char *)
"invalid bit length repeat";
418 len = (unsigned)(state->
lens[state->
have - 1]);
422 else if (here.
val == 17) {
437 strm->msg = (
char *)
"invalid bit length repeat";
442 state->
lens[state->
have++] = (
unsigned short)len;
450 if (state->
lens[256] == 0) {
451 strm->msg = (
char *)
"invalid code -- missing end-of-block";
465 strm->msg = (
char *)
"invalid literal/lengths set";
474 strm->msg = (
char *)
"invalid distances set";
478 Tracev((stderr,
"inflate: codes ok\n"));
484 if (
have >= 6 && left >= 258) {
496 if ((
unsigned)(here.
bits) <=
bits)
break;
499 if (here.
op && (here.
op & 0xf0) == 0) {
515 "inflate: literal '%c'\n" :
516 "inflate: literal 0x%02x\n", here.
val));
518 *put++ = (
unsigned char)(state->
length);
526 Tracevv((stderr,
"inflate: end of block\n"));
533 strm->msg = (
char *)
"invalid literal/length code";
539 state->
extra = (unsigned)(here.
op) & 15;
540 if (state->
extra != 0) {
550 if ((
unsigned)(here.
bits) <=
bits)
break;
553 if ((here.
op & 0xf0) == 0) {
565 strm->msg = (
char *)
"invalid distance code";
572 state->
extra = (
unsigned)(here.
op) & 15;
573 if (state->
extra != 0) {
580 strm->msg = (
char *)
"invalid distance too far back";
595 from = put - state->
offset;
604 }
while (state->
length != 0);
610 if (left < state->
wsize) {
611 if (out(out_desc, state->
window, state->
wsize - left))
639 Tracev((stderr,
"inflate: end\n"));
int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits, unsigned char FAR *window, const char *version, int stream_size)
void fixedtables(struct inflate_state FAR *state)
int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc, out_func out, void FAR *out_desc)
int ZEXPORT inflateBackEnd(z_streamp strm)
void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start)
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
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)