diff options
Diffstat (limited to 'inflate.c')
-rw-r--r-- | inflate.c | 33 |
1 files changed, 16 insertions, 17 deletions
@@ -45,7 +45,7 @@ | |||
45 | * - Rearrange window copies in inflate_fast() for speed and simplification | 45 | * - Rearrange window copies in inflate_fast() for speed and simplification |
46 | * - Unroll last copy for window match in inflate_fast() | 46 | * - Unroll last copy for window match in inflate_fast() |
47 | * - Use local copies of window variables in inflate_fast() for speed | 47 | * - Use local copies of window variables in inflate_fast() for speed |
48 | * - Pull out common write == 0 case for speed in inflate_fast() | 48 | * - Pull out common wnext == 0 case for speed in inflate_fast() |
49 | * - Make op and len in inflate_fast() unsigned for consistency | 49 | * - Make op and len in inflate_fast() unsigned for consistency |
50 | * - Add FAR to lcode and dcode declarations in inflate_fast() | 50 | * - Add FAR to lcode and dcode declarations in inflate_fast() |
51 | * - Simplified bad distance check in inflate_fast() | 51 | * - Simplified bad distance check in inflate_fast() |
@@ -117,7 +117,7 @@ z_streamp strm; | |||
117 | state->head = Z_NULL; | 117 | state->head = Z_NULL; |
118 | state->wsize = 0; | 118 | state->wsize = 0; |
119 | state->whave = 0; | 119 | state->whave = 0; |
120 | state->write = 0; | 120 | state->wnext = 0; |
121 | state->hold = 0; | 121 | state->hold = 0; |
122 | state->bits = 0; | 122 | state->bits = 0; |
123 | state->lencode = state->distcode = state->next = state->codes; | 123 | state->lencode = state->distcode = state->next = state->codes; |
@@ -152,7 +152,7 @@ int windowBits; | |||
152 | } | 152 | } |
153 | 153 | ||
154 | /* set number of window bits, free window if different */ | 154 | /* set number of window bits, free window if different */ |
155 | if (windowBits < 8 || windowBits > 15) | 155 | if (windowBits && (windowBits < 8 || windowBits > 15)) |
156 | return Z_STREAM_ERROR; | 156 | return Z_STREAM_ERROR; |
157 | if (state->wbits != windowBits && state->window != Z_NULL) { | 157 | if (state->wbits != windowBits && state->window != Z_NULL) { |
158 | ZFREE(strm, state->window); | 158 | ZFREE(strm, state->window); |
@@ -375,7 +375,7 @@ unsigned out; | |||
375 | /* if window not in use yet, initialize */ | 375 | /* if window not in use yet, initialize */ |
376 | if (state->wsize == 0) { | 376 | if (state->wsize == 0) { |
377 | state->wsize = 1U << state->wbits; | 377 | state->wsize = 1U << state->wbits; |
378 | state->write = 0; | 378 | state->wnext = 0; |
379 | state->whave = 0; | 379 | state->whave = 0; |
380 | } | 380 | } |
381 | 381 | ||
@@ -383,22 +383,22 @@ unsigned out; | |||
383 | copy = out - strm->avail_out; | 383 | copy = out - strm->avail_out; |
384 | if (copy >= state->wsize) { | 384 | if (copy >= state->wsize) { |
385 | zmemcpy(state->window, strm->next_out - state->wsize, state->wsize); | 385 | zmemcpy(state->window, strm->next_out - state->wsize, state->wsize); |
386 | state->write = 0; | 386 | state->wnext = 0; |
387 | state->whave = state->wsize; | 387 | state->whave = state->wsize; |
388 | } | 388 | } |
389 | else { | 389 | else { |
390 | dist = state->wsize - state->write; | 390 | dist = state->wsize - state->wnext; |
391 | if (dist > copy) dist = copy; | 391 | if (dist > copy) dist = copy; |
392 | zmemcpy(state->window + state->write, strm->next_out - copy, dist); | 392 | zmemcpy(state->window + state->wnext, strm->next_out - copy, dist); |
393 | copy -= dist; | 393 | copy -= dist; |
394 | if (copy) { | 394 | if (copy) { |
395 | zmemcpy(state->window, strm->next_out - copy, copy); | 395 | zmemcpy(state->window, strm->next_out - copy, copy); |
396 | state->write = copy; | 396 | state->wnext = copy; |
397 | state->whave = state->wsize; | 397 | state->whave = state->wsize; |
398 | } | 398 | } |
399 | else { | 399 | else { |
400 | state->write += dist; | 400 | state->wnext += dist; |
401 | if (state->write == state->wsize) state->write = 0; | 401 | if (state->wnext == state->wsize) state->wnext = 0; |
402 | if (state->whave < state->wsize) state->whave += dist; | 402 | if (state->whave < state->wsize) state->whave += dist; |
403 | } | 403 | } |
404 | } | 404 | } |
@@ -654,7 +654,9 @@ int flush; | |||
654 | } | 654 | } |
655 | DROPBITS(4); | 655 | DROPBITS(4); |
656 | len = BITS(4) + 8; | 656 | len = BITS(4) + 8; |
657 | if (len > state->wbits) { | 657 | if (state->wbits == 0) |
658 | state->wbits = len; | ||
659 | else if (len > state->wbits) { | ||
658 | strm->msg = (char *)"invalid window size"; | 660 | strm->msg = (char *)"invalid window size"; |
659 | state->mode = BAD; | 661 | state->mode = BAD; |
660 | break; | 662 | break; |
@@ -1128,15 +1130,12 @@ int flush; | |||
1128 | break; | 1130 | break; |
1129 | #endif | 1131 | #endif |
1130 | } | 1132 | } |
1131 | if (copy > state->write) { | 1133 | if (copy > state->wnext) { |
1132 | copy -= state->write; | 1134 | copy -= state->wnext; |
1133 | /* %% problem here if copy > state->wsize -- avoid? */ | ||
1134 | /* %% or can (state->window + state->wsize) - copy */ | ||
1135 | /* %% but really should detect and reject this case */ | ||
1136 | from = state->window + (state->wsize - copy); | 1135 | from = state->window + (state->wsize - copy); |
1137 | } | 1136 | } |
1138 | else | 1137 | else |
1139 | from = state->window + (state->write - copy); | 1138 | from = state->window + (state->wnext - copy); |
1140 | if (copy > state->length) copy = state->length; | 1139 | if (copy > state->length) copy = state->length; |
1141 | } | 1140 | } |
1142 | else { /* copy from output */ | 1141 | else { /* copy from output */ |