diff options
author | Mark Adler <madler@alumni.caltech.edu> | 2011-09-09 23:22:30 -0700 |
---|---|---|
committer | Mark Adler <madler@alumni.caltech.edu> | 2011-09-09 23:22:30 -0700 |
commit | 086e982175da84b3db958191031380794315f95f (patch) | |
tree | 12f18893b4561c1b0593931dfbb6cb300d6c00c7 /inflate.c | |
parent | 85e7d7d9ba71d95a9e6a64b98bae4fac09f06f1c (diff) | |
download | zlib-086e982175da84b3db958191031380794315f95f.tar.gz zlib-086e982175da84b3db958191031380794315f95f.tar.bz2 zlib-086e982175da84b3db958191031380794315f95f.zip |
zlib 1.2.0.4v1.2.0.4
Diffstat (limited to 'inflate.c')
-rw-r--r-- | inflate.c | 25 |
1 files changed, 17 insertions, 8 deletions
@@ -113,6 +113,7 @@ z_streamp strm; | |||
113 | state->last = 0; | 113 | state->last = 0; |
114 | state->havedict = 0; | 114 | state->havedict = 0; |
115 | state->wsize = 0; | 115 | state->wsize = 0; |
116 | state->whave = 0; | ||
116 | state->hold = 0; | 117 | state->hold = 0; |
117 | state->bits = 0; | 118 | state->bits = 0; |
118 | state->lencode = state->distcode = state->next = state->codes; | 119 | state->lencode = state->distcode = state->next = state->codes; |
@@ -150,7 +151,7 @@ int stream_size; | |||
150 | else { | 151 | else { |
151 | state->wrap = (windowBits >> 4) + 1; | 152 | state->wrap = (windowBits >> 4) + 1; |
152 | #ifdef GUNZIP | 153 | #ifdef GUNZIP |
153 | windowBits &= 15; | 154 | if (windowBits < 48) windowBits &= 15; |
154 | #endif | 155 | #endif |
155 | } | 156 | } |
156 | if (windowBits < 8 || windowBits > 15) { | 157 | if (windowBits < 8 || windowBits > 15) { |
@@ -320,6 +321,7 @@ unsigned out; | |||
320 | if (state->wsize == 0) { | 321 | if (state->wsize == 0) { |
321 | state->wsize = 1U << state->wbits; | 322 | state->wsize = 1U << state->wbits; |
322 | state->write = 0; | 323 | state->write = 0; |
324 | state->whave = 0; | ||
323 | } | 325 | } |
324 | 326 | ||
325 | /* copy state->wsize or less output bytes into the circular window */ | 327 | /* copy state->wsize or less output bytes into the circular window */ |
@@ -327,6 +329,7 @@ unsigned out; | |||
327 | if (copy >= state->wsize) { | 329 | if (copy >= state->wsize) { |
328 | zmemcpy(state->window, strm->next_out - state->wsize, state->wsize); | 330 | zmemcpy(state->window, strm->next_out - state->wsize, state->wsize); |
329 | state->write = 0; | 331 | state->write = 0; |
332 | state->whave = state->wsize; | ||
330 | } | 333 | } |
331 | else { | 334 | else { |
332 | dist = state->wsize - state->write; | 335 | dist = state->wsize - state->write; |
@@ -336,10 +339,12 @@ unsigned out; | |||
336 | if (copy) { | 339 | if (copy) { |
337 | zmemcpy(state->window, strm->next_out - copy, copy); | 340 | zmemcpy(state->window, strm->next_out - copy, copy); |
338 | state->write = copy; | 341 | state->write = copy; |
342 | state->whave = state->wsize; | ||
339 | } | 343 | } |
340 | else { | 344 | else { |
341 | state->write += dist; | 345 | state->write += dist; |
342 | if (state->write == state->wsize) state->write = 0; | 346 | if (state->write == state->wsize) state->write = 0; |
347 | if (state->whave < state->wsize) state->whave += dist; | ||
343 | } | 348 | } |
344 | } | 349 | } |
345 | return 0; | 350 | return 0; |
@@ -531,13 +536,14 @@ z_streamp strm; | |||
531 | int flush; | 536 | int flush; |
532 | { | 537 | { |
533 | struct inflate_state FAR *state; | 538 | struct inflate_state FAR *state; |
534 | unsigned char *next, *put; /* next input and output */ | 539 | unsigned char FAR *next; /* next input */ |
540 | unsigned char FAR *put; /* next output */ | ||
535 | unsigned have, left; /* available input and output */ | 541 | unsigned have, left; /* available input and output */ |
536 | unsigned long hold; /* bit buffer */ | 542 | unsigned long hold; /* bit buffer */ |
537 | unsigned bits; /* bits in bit buffer */ | 543 | unsigned bits; /* bits in bit buffer */ |
538 | unsigned in, out; /* save starting available input and output */ | 544 | unsigned in, out; /* save starting available input and output */ |
539 | unsigned copy; /* number of stored or match bytes to copy */ | 545 | unsigned copy; /* number of stored or match bytes to copy */ |
540 | unsigned char *from; /* where to copy match bytes from */ | 546 | unsigned char FAR *from; /* where to copy match bytes from */ |
541 | code this; /* current decoding table entry */ | 547 | code this; /* current decoding table entry */ |
542 | code last; /* parent table entry */ | 548 | code last; /* parent table entry */ |
543 | unsigned len; /* length to copy for repeats, bits to drop */ | 549 | unsigned len; /* length to copy for repeats, bits to drop */ |
@@ -956,8 +962,7 @@ int flush; | |||
956 | state->offset += BITS(state->extra); | 962 | state->offset += BITS(state->extra); |
957 | DROPBITS(state->extra); | 963 | DROPBITS(state->extra); |
958 | } | 964 | } |
959 | if (state->offset > (state->wsize ? state->wsize : | 965 | if (state->offset > state->whave + out - left) { |
960 | out - left)) { | ||
961 | strm->msg = (char *)"invalid distance too far back"; | 966 | strm->msg = (char *)"invalid distance too far back"; |
962 | state->mode = BAD; | 967 | state->mode = BAD; |
963 | break; | 968 | break; |
@@ -1108,12 +1113,16 @@ uInt dictLength; | |||
1108 | state->mode = MEM; | 1113 | state->mode = MEM; |
1109 | return Z_MEM_ERROR; | 1114 | return Z_MEM_ERROR; |
1110 | } | 1115 | } |
1111 | if (dictLength > state->wsize) | 1116 | if (dictLength > state->wsize) { |
1112 | zmemcpy(state->window, dictionary + dictLength - state->wsize, | 1117 | zmemcpy(state->window, dictionary + dictLength - state->wsize, |
1113 | state->wsize); | 1118 | state->wsize); |
1114 | else | 1119 | state->whave = state->wsize; |
1120 | } | ||
1121 | else { | ||
1115 | zmemcpy(state->window + state->wsize - dictLength, dictionary, | 1122 | zmemcpy(state->window + state->wsize - dictLength, dictionary, |
1116 | dictLength); | 1123 | dictLength); |
1124 | state->whave = dictLength; | ||
1125 | } | ||
1117 | state->havedict = 1; | 1126 | state->havedict = 1; |
1118 | Tracev((stderr, "inflate: dictionary set\n")); | 1127 | Tracev((stderr, "inflate: dictionary set\n")); |
1119 | return Z_OK; | 1128 | return Z_OK; |
@@ -1131,7 +1140,7 @@ uInt dictLength; | |||
1131 | zero for the first call. | 1140 | zero for the first call. |
1132 | */ | 1141 | */ |
1133 | local unsigned syncsearch(have, buf, len) | 1142 | local unsigned syncsearch(have, buf, len) |
1134 | unsigned *have; | 1143 | unsigned FAR *have; |
1135 | unsigned char FAR *buf; | 1144 | unsigned char FAR *buf; |
1136 | unsigned len; | 1145 | unsigned len; |
1137 | { | 1146 | { |