56 value &= (1
L <<
bits) - 1;
70 state = &
WS(strm)->inflate_state;
75 windowBits = -windowBits;
78 state->
wrap = (windowBits >> 4) + 1;
80 if (windowBits < 8 || windowBits > 15) {
83 state->
wbits = (unsigned)windowBits;
84 state->
window = &
WS(strm)->working_window[0];
116 static void zlib_updatewindow(
z_streamp strm,
unsigned out)
132 if (dist > copy) dist = copy;
161 static int zlib_inflateSyncPacket(
z_streamp strm)
178 #define UPDATE(check, buf, len) zlib_adler32(check, buf, len)
183 put = strm->next_out; \
184 left = strm->avail_out; \
185 next = strm->next_in; \
186 have = strm->avail_in; \
187 hold = state->hold; \
188 bits = state->bits; \
194 strm->next_out = put; \
195 strm->avail_out = left; \
196 strm->next_in = next; \
197 strm->avail_in = have; \
198 state->hold = hold; \
199 state->bits = bits; \
213 if (have == 0) goto inf_leave; \
215 hold += (unsigned long)(*next++) << bits; \
221 #define NEEDBITS(n) \
223 while (bits < (unsigned)(n)) \
229 ((unsigned)hold & ((1U << (n)) - 1))
232 #define DROPBITS(n) \
235 bits -= (unsigned)(n); \
247 ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
248 (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
335 const unsigned char *
next;
347 static const unsigned short order[19] =
348 {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
365 switch (state->
mode) {
367 if (state->
wrap == 0) {
373 ((
BITS(8) << 8) + (hold >> 8)) % 31) {
374 strm->
msg = (
char *)
"incorrect header check";
379 strm->
msg = (
char *)
"unknown compression method";
385 if (len > state->
wbits) {
386 strm->
msg = (
char *)
"invalid window size";
390 state->
dmax = 1
U << len;
408 if (flush ==
Z_BLOCK)
goto inf_leave;
423 zlib_fixedtables(state);
430 strm->
msg = (
char *)
"invalid block type";
438 if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
439 strm->
msg = (
char *)
"invalid stored block lengths";
443 state->
length = (unsigned)hold & 0xffff;
449 if (copy > have) copy =
have;
450 if (copy > left) copy =
left;
451 if (copy == 0)
goto inf_leave;
470 #ifndef PKZIP_BUG_WORKAROUND
471 if (state->
nlen > 286 || state->
ndist > 30) {
472 strm->
msg = (
char *)
"too many length or distance symbols";
485 while (state->
have < 19)
486 state->
lens[order[state->
have++]] = 0;
493 strm->
msg = (
char *)
"invalid code lengths set";
503 if ((
unsigned)(this.bits) <= bits)
break;
512 if (this.
val == 16) {
515 if (state->
have == 0) {
516 strm->
msg = (
char *)
"invalid bit length repeat";
524 else if (this.
val == 17) {
539 strm->
msg = (
char *)
"invalid bit length repeat";
558 strm->
msg = (
char *)
"invalid literal/lengths set";
567 strm->
msg = (
char *)
"invalid distances set";
573 if (have >= 6 && left >= 258) {
581 if ((
unsigned)(this.bits) <= bits)
break;
584 if (this.
op && (this.
op & 0xf0) == 0) {
589 if ((
unsigned)(last.
bits + this.
bits) <= bits)
break;
596 if ((
int)(this.
op) == 0) {
605 strm->
msg = (
char *)
"invalid literal/length code";
609 state->
extra = (unsigned)(this.
op) & 15;
621 if ((
unsigned)(this.bits) <= bits)
break;
624 if ((this.
op & 0xf0) == 0) {
629 if ((
unsigned)(last.
bits + this.
bits) <= bits)
break;
636 strm->
msg = (
char *)
"invalid distance code";
641 state->
extra = (unsigned)(this.
op) & 15;
649 #ifdef INFLATE_STRICT
651 strm->
msg = (
char *)
"invalid distance too far back";
657 strm->
msg = (
char *)
"invalid distance too far back";
663 if (left == 0)
goto inf_leave;
665 if (state->
offset > copy) {
666 copy = state->
offset - copy;
667 if (copy > state->
write) {
668 copy -= state->
write;
676 from = put - state->
offset;
679 if (copy > left) copy =
left;
688 if (left == 0)
goto inf_leave;
705 strm->
msg = (
char *)
"incorrect data check";
733 zlib_updatewindow(strm, out);
740 if (state->
wrap && out)
749 return zlib_inflateSyncPacket(strm);
751 if (((in == 0 && out == 0) || flush ==
Z_FINISH) && ret ==
Z_OK)
779 id = zlib_adler32(0L,
NULL, 0);
780 id = zlib_adler32(
id, dictionary, dictLength);
781 if (
id != state->
check)
786 zlib_updatewindow(strm, strm->
avail_out);
788 if (dictLength > state->
wsize) {
796 state->
whave = dictLength;
815 static unsigned zlib_syncsearch(
unsigned *
have,
unsigned char *
buf,
823 while (next < len && got < 4) {
824 if ((
int)(buf[next]) == (got < 2 ? 0 : 0xff))
841 unsigned long in,
out;
842 unsigned char buf[4];
856 while (state->
bits >= 8) {
857 buf[len++] = (
unsigned char)(state->
hold);
862 zlib_syncsearch(&(state->
have), buf, len);