aboutsummaryrefslogtreecommitdiff
path: root/inflate.c
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2011-09-09 23:22:10 -0700
committerMark Adler <madler@alumni.caltech.edu>2011-09-09 23:22:10 -0700
commit8e34b3a8024c028dd9fd21d70525fc6d215efde5 (patch)
tree896a32f54abdf42ae3c1bb3c5d5627668b481ce4 /inflate.c
parent13a294f044ef0a89b2dcbfbb5d4d4c792673348e (diff)
downloadzlib-8e34b3a8024c028dd9fd21d70525fc6d215efde5.tar.gz
zlib-8e34b3a8024c028dd9fd21d70525fc6d215efde5.tar.bz2
zlib-8e34b3a8024c028dd9fd21d70525fc6d215efde5.zip
zlib 1.2.0.2v1.2.0.2
Diffstat (limited to 'inflate.c')
-rw-r--r--inflate.c61
1 files changed, 34 insertions, 27 deletions
diff --git a/inflate.c b/inflate.c
index 1da2776..0fd158d 100644
--- a/inflate.c
+++ b/inflate.c
@@ -77,7 +77,7 @@
77 * and buffer address return values for the input function 77 * and buffer address return values for the input function
78 * - Check next_in and next_out for Z_NULL on entry to inflate() 78 * - Check next_in and next_out for Z_NULL on entry to inflate()
79 * 79 *
80 * The history for versions past 1.2.0 are in ChangeLog in zlib distribution. 80 * The history for versions after 1.2.0 are in ChangeLog in zlib distribution.
81 */ 81 */
82 82
83#include "zutil.h" 83#include "zutil.h"
@@ -147,8 +147,12 @@ int stream_size;
147 state->wrap = 0; 147 state->wrap = 0;
148 windowBits = -windowBits; 148 windowBits = -windowBits;
149 } 149 }
150 else 150 else {
151 state->wrap = 1; 151 state->wrap = (windowBits >> 4) + 1;
152#ifdef GUNZIP
153 windowBits &= 15;
154#endif
155 }
152 if (windowBits < 8 || windowBits > 15) { 156 if (windowBits < 8 || windowBits > 15) {
153 ZFREE(strm, state); 157 ZFREE(strm, state);
154 strm->state = Z_NULL; 158 strm->state = Z_NULL;
@@ -403,7 +407,7 @@ unsigned out;
403 if there is no input available. */ 407 if there is no input available. */
404#define PULLBYTE() \ 408#define PULLBYTE() \
405 do { \ 409 do { \
406 if (have == 0) goto leave; \ 410 if (have == 0) goto inf_leave; \
407 have--; \ 411 have--; \
408 hold += (unsigned long)(*next++) << bits; \ 412 hold += (unsigned long)(*next++) << bits; \
409 bits += 8; \ 413 bits += 8; \
@@ -502,14 +506,14 @@ unsigned out;
502 complete that state. Those states are copying stored data, writing a 506 complete that state. Those states are copying stored data, writing a
503 literal byte, and copying a matching string. 507 literal byte, and copying a matching string.
504 508
505 When returning, a "goto leave" is used to update the total counters, update 509 When returning, a "goto inf_leave" is used to update the total counters,
506 the check value, and determine whether any progress has been made during 510 update the check value, and determine whether any progress has been made
507 that inflate() call in order to return the proper return code. Progress is 511 during that inflate() call in order to return the proper return code.
508 defined as a change in either strm->avail_in or strm->avail_out. When there 512 Progress is defined as a change in either strm->avail_in or strm->avail_out.
509 is a window, goto leave will update the window with the last output written. 513 When there is a window, goto inf_leave will update the window with the last
510 If a goto leave occurs in the middle of decompression and there is no window 514 output written. If a goto inf_leave occurs in the middle of decompression
511 currently, goto leave will create one and copy output to the window for the 515 and there is no window currently, goto inf_leave will create one and copy
512 next call of inflate(). 516 output to the window for the next call of inflate().
513 517
514 In this implementation, the flush parameter of inflate() only affects the 518 In this implementation, the flush parameter of inflate() only affects the
515 return code (per zlib.h). inflate() always writes as much as possible to 519 return code (per zlib.h). inflate() always writes as much as possible to
@@ -562,16 +566,19 @@ int flush;
562 } 566 }
563 NEEDBITS(16); 567 NEEDBITS(16);
564#ifdef GUNZIP 568#ifdef GUNZIP
565 if (hold == 0x8b1f) { /* gzip header */ 569 if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
566 state->check = crc32(0L, Z_NULL, 0); 570 state->check = crc32(0L, Z_NULL, 0);
567 CRC2(state->check, hold); 571 CRC2(state->check, hold);
568 INITBITS(); 572 INITBITS();
569 state->mode = FLAGS; 573 state->mode = FLAGS;
570 break; 574 break;
571 } 575 }
572 state->flags = 0; /* expect zlib header */ 576 state->flags = 0; /* expect zlib header */
577 if (!(state->wrap & 1) || /* check if zlib header allowed */
578#else
579 if (
573#endif 580#endif
574 if (((BITS(8) << 8) + (hold >> 8)) % 31) { 581 ((BITS(8) << 8) + (hold >> 8)) % 31) {
575 strm->msg = (char *)"incorrect header check"; 582 strm->msg = (char *)"incorrect header check";
576 state->mode = BAD; 583 state->mode = BAD;
577 break; 584 break;
@@ -638,12 +645,12 @@ int flush;
638 next += copy; 645 next += copy;
639 state->length -= copy; 646 state->length -= copy;
640 } 647 }
641 if (state->length) goto leave; 648 if (state->length) goto inf_leave;
642 } 649 }
643 state->mode = NAME; 650 state->mode = NAME;
644 case NAME: 651 case NAME:
645 if (state->flags & 0x0800) { 652 if (state->flags & 0x0800) {
646 if (have == 0) goto leave; 653 if (have == 0) goto inf_leave;
647 copy = 0; 654 copy = 0;
648 do { 655 do {
649 len = (unsigned)(next[copy++]); 656 len = (unsigned)(next[copy++]);
@@ -652,12 +659,12 @@ int flush;
652 state->check = crc32(state->check, next, copy); 659 state->check = crc32(state->check, next, copy);
653 have -= copy; 660 have -= copy;
654 next += copy; 661 next += copy;
655 if (len) goto leave; 662 if (len) goto inf_leave;
656 } 663 }
657 state->mode = COMMENT; 664 state->mode = COMMENT;
658 case COMMENT: 665 case COMMENT:
659 if (state->flags & 0x1000) { 666 if (state->flags & 0x1000) {
660 if (have == 0) goto leave; 667 if (have == 0) goto inf_leave;
661 copy = 0; 668 copy = 0;
662 do { 669 do {
663 len = (unsigned)(next[copy++]); 670 len = (unsigned)(next[copy++]);
@@ -666,7 +673,7 @@ int flush;
666 state->check = crc32(state->check, next, copy); 673 state->check = crc32(state->check, next, copy);
667 have -= copy; 674 have -= copy;
668 next += copy; 675 next += copy;
669 if (len) goto leave; 676 if (len) goto inf_leave;
670 } 677 }
671 state->mode = HCRC; 678 state->mode = HCRC;
672 case HCRC: 679 case HCRC:
@@ -745,7 +752,7 @@ int flush;
745 if (copy) { 752 if (copy) {
746 if (copy > have) copy = have; 753 if (copy > have) copy = have;
747 if (copy > left) copy = left; 754 if (copy > left) copy = left;
748 if (copy == 0) goto leave; 755 if (copy == 0) goto inf_leave;
749 zmemcpy(put, next, copy); 756 zmemcpy(put, next, copy);
750 have -= copy; 757 have -= copy;
751 next += copy; 758 next += copy;
@@ -958,7 +965,7 @@ int flush;
958 Tracevv((stderr, "inflate: distance %u\n", state->offset)); 965 Tracevv((stderr, "inflate: distance %u\n", state->offset));
959 state->mode = MATCH; 966 state->mode = MATCH;
960 case MATCH: 967 case MATCH:
961 if (left == 0) goto leave; 968 if (left == 0) goto inf_leave;
962 copy = out - left; 969 copy = out - left;
963 if (state->offset > copy) { /* copy from window */ 970 if (state->offset > copy) { /* copy from window */
964 copy = state->offset - copy; 971 copy = state->offset - copy;
@@ -983,7 +990,7 @@ int flush;
983 if (state->length == 0) state->mode = LEN; 990 if (state->length == 0) state->mode = LEN;
984 break; 991 break;
985 case LIT: 992 case LIT:
986 if (left == 0) goto leave; 993 if (left == 0) goto inf_leave;
987 *put++ = (unsigned char)(state->length); 994 *put++ = (unsigned char)(state->length);
988 left--; 995 left--;
989 state->mode = LEN; 996 state->mode = LEN;
@@ -1015,7 +1022,7 @@ int flush;
1015 case LENGTH: 1022 case LENGTH:
1016 if (state->wrap && state->flags) { 1023 if (state->wrap && state->flags) {
1017 NEEDBITS(32); 1024 NEEDBITS(32);
1018 if (hold != (state->total & 0xffffffff)) { 1025 if (hold != (state->total & 0xffffffffUL)) {
1019 strm->msg = (char *)"incorrect length check"; 1026 strm->msg = (char *)"incorrect length check";
1020 state->mode = BAD; 1027 state->mode = BAD;
1021 break; 1028 break;
@@ -1027,10 +1034,10 @@ int flush;
1027 state->mode = DONE; 1034 state->mode = DONE;
1028 case DONE: 1035 case DONE:
1029 ret = Z_STREAM_END; 1036 ret = Z_STREAM_END;
1030 goto leave; 1037 goto inf_leave;
1031 case BAD: 1038 case BAD:
1032 ret = Z_DATA_ERROR; 1039 ret = Z_DATA_ERROR;
1033 goto leave; 1040 goto inf_leave;
1034 case MEM: 1041 case MEM:
1035 return Z_MEM_ERROR; 1042 return Z_MEM_ERROR;
1036 case SYNC: 1043 case SYNC:
@@ -1044,7 +1051,7 @@ int flush;
1044 error. Call updatewindow() to create and/or update the window state. 1051 error. Call updatewindow() to create and/or update the window state.
1045 Note: a memory error from inflate() is non-recoverable. 1052 Note: a memory error from inflate() is non-recoverable.
1046 */ 1053 */
1047 leave: 1054 inf_leave:
1048 RESTORE(); 1055 RESTORE();
1049 if (state->wsize || (state->mode < CHECK && out != strm->avail_out)) 1056 if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
1050 if (updatewindow(strm, out)) { 1057 if (updatewindow(strm, out)) {