40 stream_size != (
int)(
sizeof(
z_stream)))
43 windowBits < 8 || windowBits > 15)
46 if (strm->zalloc == (alloc_func)0) {
50 if (strm->zfree == (free_func)0) strm->zfree =
zcfree;
54 Tracev((stderr,
"inflate: allocated\n"));
57 state->
wbits = windowBits;
58 state->
wsize = 1U << windowBits;
78 static int virgin = 1;
80 static code fixed[544];
89 while (sym < 144) state->lens[sym++] = 8;
90 while (sym < 256) state->lens[sym++] = 9;
91 while (sym < 280) state->lens[sym++] = 7;
92 while (sym < 288) state->lens[sym++] = 8;
100 while (sym < 32) state->lens[sym++] = 5;
122 put = strm->next_out; \
123 left = strm->avail_out; \
124 next = strm->next_in; \
125 have = strm->avail_in; \
126 hold = state->hold; \
127 bits = state->bits; \
133 strm->next_out = put; \
134 strm->avail_out = left; \
135 strm->next_in = next; \
136 strm->avail_in = have; \
137 state->hold = hold; \
138 state->bits = bits; \
153 have = in(in_desc, &next); \
168 hold += (unsigned long)(*next++) << bits; \
175 #define NEEDBITS(n) \
177 while (bits < (unsigned)(n)) \
183 ((unsigned)hold & ((1U << (n)) - 1))
186 #define DROPBITS(n) \
189 bits -= (unsigned)(n); \
205 put = state->window; \
206 left = state->wsize; \
207 state->whave = left; \
208 if (out(out_desc, put, left)) { \
245 unsigned char FAR *
next;
246 unsigned char FAR *put;
251 unsigned char FAR *from;
256 static const unsigned short order[19] =
257 {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
269 next = strm->next_in;
270 have = next !=
Z_NULL ? strm->avail_in : 0;
278 switch (state->
mode) {
291 Tracev((stderr,
"inflate: stored block%s\n",
292 state->
last ?
" (last)" :
""));
297 Tracev((stderr,
"inflate: fixed codes block%s\n",
298 state->
last ?
" (last)" :
""));
302 Tracev((stderr,
"inflate: dynamic codes block%s\n",
303 state->
last ?
" (last)" :
""));
307 strm->msg = (
char *)
"invalid block type";
317 if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
318 strm->msg = (
char *)
"invalid stored block lengths";
322 state->
length = (unsigned)hold & 0xffff;
323 Tracev((stderr,
"inflate: stored length %u\n",
328 while (state->
length != 0) {
332 if (copy > have) copy =
have;
333 if (copy > left) copy = left;
341 Tracev((stderr,
"inflate: stored end\n"));
354 #ifndef PKZIP_BUG_WORKAROUND
355 if (state->
nlen > 286 || state->
ndist > 30) {
356 strm->msg = (
char *)
"too many length or distance symbols";
361 Tracev((stderr,
"inflate: table sizes ok\n"));
367 state->
lens[order[state->
have++]] = (
unsigned short)
BITS(3);
370 while (state->
have < 19)
371 state->
lens[order[state->
have++]] = 0;
378 strm->msg = (
char *)
"invalid code lengths set";
382 Tracev((stderr,
"inflate: code lengths ok\n"));
389 if ((
unsigned)(here.
bits) <= bits)
break;
398 if (here.
val == 16) {
401 if (state->
have == 0) {
402 strm->msg = (
char *)
"invalid bit length repeat";
406 len = (unsigned)(state->
lens[state->
have - 1]);
410 else if (here.
val == 17) {
425 strm->msg = (
char *)
"invalid bit length repeat";
430 state->
lens[state->
have++] = (
unsigned short)len;
438 if (state->
lens[256] == 0) {
439 strm->msg = (
char *)
"invalid code -- missing end-of-block";
453 strm->msg = (
char *)
"invalid literal/lengths set";
462 strm->msg = (
char *)
"invalid distances set";
466 Tracev((stderr,
"inflate: codes ok\n"));
471 if (have >= 6 && left >= 258) {
483 if ((
unsigned)(here.
bits) <= bits)
break;
486 if (here.
op && (here.
op & 0xf0) == 0) {
491 if ((
unsigned)(last.
bits + here.
bits) <= bits)
break;
502 "inflate: literal '%c'\n" :
503 "inflate: literal 0x%02x\n", here.
val));
505 *put++ = (
unsigned char)(state->
length);
513 Tracevv((stderr,
"inflate: end of block\n"));
520 strm->msg = (
char *)
"invalid literal/length code";
526 state->
extra = (unsigned)(here.
op) & 15;
527 if (state->
extra != 0) {
537 if ((
unsigned)(here.
bits) <= bits)
break;
540 if ((here.
op & 0xf0) == 0) {
545 if ((
unsigned)(last.
bits + here.
bits) <= bits)
break;
552 strm->msg = (
char *)
"invalid distance code";
559 state->
extra = (
unsigned)(here.
op) & 15;
560 if (state->
extra != 0) {
567 strm->msg = (
char *)
"invalid distance too far back";
582 from = put - state->
offset;
591 }
while (state->
length != 0);
597 if (left < state->
wsize) {
598 if (out(out_desc, state->
window, state->
wsize - left))
614 strm->next_in =
next;
615 strm->avail_in =
have;
621 if (strm ==
Z_NULL || strm->state ==
Z_NULL || strm->zfree == (free_func)0)
623 ZFREE(strm, strm->state);
625 Tracev((stderr,
"inflate: end\n"));
ABC_NAMESPACE_IMPL_START local void fixedtables OF((struct inflate_state FAR *state))
static void copy(const T &from, T &to)
int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc, out_func out, void FAR *out_desc)
code const FAR * distcode
static const code lenfix[512]
int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits, unsigned char FAR *window, const char *version, int stream_size)
for(p=first;p->value< newval;p=p->next)
#define ZALLOC(strm, items, size)
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)
static const code distfix[32]
#define ZFREE(strm, addr)
#define ABC_NAMESPACE_IMPL_END
int ZEXPORT inflateBackEnd(z_streamp strm)
void ZLIB_INTERNAL zmemcpy(Bytef *dest, const Bytef *source, uInt len)
#define ABC_NAMESPACE_IMPL_START
local void fixedtables(struct inflate_state FAR *state)
unsigned char FAR * window
static char * bits(int n)
voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size)
void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr)