inflate.c (a15cb219c6f2b8ed16179c2fce882a2ff327b753) inflate.c (cd8822075a38d0734e74b1735e4b5dbef9789170)
1/* inflate.c -- zlib decompression
1/* inflate.c -- zlib decompression
2 * Copyright (C) 1995-2016 Mark Adler
2 * Copyright (C) 1995-2022 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/*
7 * Change history:
8 *
9 * 1.2.beta0 24 Nov 2002
10 * - First version -- complete rewrite of inflate to simplify code, avoid

--- 114 unchanged lines hidden (view full) ---

125 state = (struct inflate_state FAR *)strm->state;
126 strm->total_in = strm->total_out = state->total = 0;
127 strm->msg = Z_NULL;
128 if (state->wrap) /* to support ill-conceived Java test suite */
129 strm->adler = state->wrap & 1;
130 state->mode = HEAD;
131 state->last = 0;
132 state->havedict = 0;
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/*
7 * Change history:
8 *
9 * 1.2.beta0 24 Nov 2002
10 * - First version -- complete rewrite of inflate to simplify code, avoid

--- 114 unchanged lines hidden (view full) ---

125 state = (struct inflate_state FAR *)strm->state;
126 strm->total_in = strm->total_out = state->total = 0;
127 strm->msg = Z_NULL;
128 if (state->wrap) /* to support ill-conceived Java test suite */
129 strm->adler = state->wrap & 1;
130 state->mode = HEAD;
131 state->last = 0;
132 state->havedict = 0;
133 state->flags = -1;
133 state->dmax = 32768U;
134 state->head = Z_NULL;
135 state->hold = 0;
136 state->bits = 0;
137 state->lencode = state->distcode = state->next = state->codes;
138 state->sane = 1;
139 state->back = -1;
140 Tracev((stderr, "inflate: reset\n"));

--- 301 unchanged lines hidden (view full) ---

442 }
443 return 0;
444}
445
446/* Macros for inflate(): */
447
448/* check function to use adler32() for zlib or crc32() for gzip */
449#ifdef GUNZIP
134 state->dmax = 32768U;
135 state->head = Z_NULL;
136 state->hold = 0;
137 state->bits = 0;
138 state->lencode = state->distcode = state->next = state->codes;
139 state->sane = 1;
140 state->back = -1;
141 Tracev((stderr, "inflate: reset\n"));

--- 301 unchanged lines hidden (view full) ---

443 }
444 return 0;
445}
446
447/* Macros for inflate(): */
448
449/* check function to use adler32() for zlib or crc32() for gzip */
450#ifdef GUNZIP
450# define UPDATE(check, buf, len) \
451# define UPDATE_CHECK(check, buf, len) \
451 (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
452#else
452 (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
453#else
453# define UPDATE(check, buf, len) adler32(check, buf, len)
454# define UPDATE_CHECK(check, buf, len) adler32(check, buf, len)
454#endif
455
456/* check macros for header crc */
457#ifdef GUNZIP
458# define CRC2(check, word) \
459 do { \
460 hbuf[0] = (unsigned char)(word); \
461 hbuf[1] = (unsigned char)((word) >> 8); \

--- 203 unchanged lines hidden (view full) ---

665 if (state->wbits == 0)
666 state->wbits = 15;
667 state->check = crc32(0L, Z_NULL, 0);
668 CRC2(state->check, hold);
669 INITBITS();
670 state->mode = FLAGS;
671 break;
672 }
455#endif
456
457/* check macros for header crc */
458#ifdef GUNZIP
459# define CRC2(check, word) \
460 do { \
461 hbuf[0] = (unsigned char)(word); \
462 hbuf[1] = (unsigned char)((word) >> 8); \

--- 203 unchanged lines hidden (view full) ---

666 if (state->wbits == 0)
667 state->wbits = 15;
668 state->check = crc32(0L, Z_NULL, 0);
669 CRC2(state->check, hold);
670 INITBITS();
671 state->mode = FLAGS;
672 break;
673 }
673 state->flags = 0; /* expect zlib header */
674 if (state->head != Z_NULL)
675 state->head->done = -1;
676 if (!(state->wrap & 1) || /* check if zlib header allowed */
677#else
678 if (
679#endif
680 ((BITS(8) << 8) + (hold >> 8)) % 31) {
681 strm->msg = (char *)"incorrect header check";

--- 10 unchanged lines hidden (view full) ---

692 if (state->wbits == 0)
693 state->wbits = len;
694 if (len > 15 || len > state->wbits) {
695 strm->msg = (char *)"invalid window size";
696 state->mode = BAD;
697 break;
698 }
699 state->dmax = 1U << len;
674 if (state->head != Z_NULL)
675 state->head->done = -1;
676 if (!(state->wrap & 1) || /* check if zlib header allowed */
677#else
678 if (
679#endif
680 ((BITS(8) << 8) + (hold >> 8)) % 31) {
681 strm->msg = (char *)"incorrect header check";

--- 10 unchanged lines hidden (view full) ---

692 if (state->wbits == 0)
693 state->wbits = len;
694 if (len > 15 || len > state->wbits) {
695 strm->msg = (char *)"invalid window size";
696 state->mode = BAD;
697 break;
698 }
699 state->dmax = 1U << len;
700 state->flags = 0; /* indicate zlib header */
700 Tracev((stderr, "inflate: zlib header ok\n"));
701 strm->adler = state->check = adler32(0L, Z_NULL, 0);
702 state->mode = hold & 0x200 ? DICTID : TYPE;
703 INITBITS();
704 break;
705#ifdef GUNZIP
706 case FLAGS:
707 NEEDBITS(16);

--- 9 unchanged lines hidden (view full) ---

717 break;
718 }
719 if (state->head != Z_NULL)
720 state->head->text = (int)((hold >> 8) & 1);
721 if ((state->flags & 0x0200) && (state->wrap & 4))
722 CRC2(state->check, hold);
723 INITBITS();
724 state->mode = TIME;
701 Tracev((stderr, "inflate: zlib header ok\n"));
702 strm->adler = state->check = adler32(0L, Z_NULL, 0);
703 state->mode = hold & 0x200 ? DICTID : TYPE;
704 INITBITS();
705 break;
706#ifdef GUNZIP
707 case FLAGS:
708 NEEDBITS(16);

--- 9 unchanged lines hidden (view full) ---

718 break;
719 }
720 if (state->head != Z_NULL)
721 state->head->text = (int)((hold >> 8) & 1);
722 if ((state->flags & 0x0200) && (state->wrap & 4))
723 CRC2(state->check, hold);
724 INITBITS();
725 state->mode = TIME;
726 /* fallthrough */
725 case TIME:
726 NEEDBITS(32);
727 if (state->head != Z_NULL)
728 state->head->time = hold;
729 if ((state->flags & 0x0200) && (state->wrap & 4))
730 CRC4(state->check, hold);
731 INITBITS();
732 state->mode = OS;
727 case TIME:
728 NEEDBITS(32);
729 if (state->head != Z_NULL)
730 state->head->time = hold;
731 if ((state->flags & 0x0200) && (state->wrap & 4))
732 CRC4(state->check, hold);
733 INITBITS();
734 state->mode = OS;
735 /* fallthrough */
733 case OS:
734 NEEDBITS(16);
735 if (state->head != Z_NULL) {
736 state->head->xflags = (int)(hold & 0xff);
737 state->head->os = (int)(hold >> 8);
738 }
739 if ((state->flags & 0x0200) && (state->wrap & 4))
740 CRC2(state->check, hold);
741 INITBITS();
742 state->mode = EXLEN;
736 case OS:
737 NEEDBITS(16);
738 if (state->head != Z_NULL) {
739 state->head->xflags = (int)(hold & 0xff);
740 state->head->os = (int)(hold >> 8);
741 }
742 if ((state->flags & 0x0200) && (state->wrap & 4))
743 CRC2(state->check, hold);
744 INITBITS();
745 state->mode = EXLEN;
746 /* fallthrough */
743 case EXLEN:
744 if (state->flags & 0x0400) {
745 NEEDBITS(16);
746 state->length = (unsigned)(hold);
747 if (state->head != Z_NULL)
748 state->head->extra_len = (unsigned)hold;
749 if ((state->flags & 0x0200) && (state->wrap & 4))
750 CRC2(state->check, hold);
751 INITBITS();
752 }
753 else if (state->head != Z_NULL)
754 state->head->extra = Z_NULL;
755 state->mode = EXTRA;
747 case EXLEN:
748 if (state->flags & 0x0400) {
749 NEEDBITS(16);
750 state->length = (unsigned)(hold);
751 if (state->head != Z_NULL)
752 state->head->extra_len = (unsigned)hold;
753 if ((state->flags & 0x0200) && (state->wrap & 4))
754 CRC2(state->check, hold);
755 INITBITS();
756 }
757 else if (state->head != Z_NULL)
758 state->head->extra = Z_NULL;
759 state->mode = EXTRA;
760 /* fallthrough */
756 case EXTRA:
757 if (state->flags & 0x0400) {
758 copy = state->length;
759 if (copy > have) copy = have;
760 if (copy) {
761 if (state->head != Z_NULL &&
762 state->head->extra != Z_NULL) {
763 len = state->head->extra_len - state->length;

--- 6 unchanged lines hidden (view full) ---

770 have -= copy;
771 next += copy;
772 state->length -= copy;
773 }
774 if (state->length) goto inf_leave;
775 }
776 state->length = 0;
777 state->mode = NAME;
761 case EXTRA:
762 if (state->flags & 0x0400) {
763 copy = state->length;
764 if (copy > have) copy = have;
765 if (copy) {
766 if (state->head != Z_NULL &&
767 state->head->extra != Z_NULL) {
768 len = state->head->extra_len - state->length;

--- 6 unchanged lines hidden (view full) ---

775 have -= copy;
776 next += copy;
777 state->length -= copy;
778 }
779 if (state->length) goto inf_leave;
780 }
781 state->length = 0;
782 state->mode = NAME;
783 /* fallthrough */
778 case NAME:
779 if (state->flags & 0x0800) {
780 if (have == 0) goto inf_leave;
781 copy = 0;
782 do {
783 len = (unsigned)(next[copy++]);
784 if (state->head != Z_NULL &&
785 state->head->name != Z_NULL &&

--- 5 unchanged lines hidden (view full) ---

791 have -= copy;
792 next += copy;
793 if (len) goto inf_leave;
794 }
795 else if (state->head != Z_NULL)
796 state->head->name = Z_NULL;
797 state->length = 0;
798 state->mode = COMMENT;
784 case NAME:
785 if (state->flags & 0x0800) {
786 if (have == 0) goto inf_leave;
787 copy = 0;
788 do {
789 len = (unsigned)(next[copy++]);
790 if (state->head != Z_NULL &&
791 state->head->name != Z_NULL &&

--- 5 unchanged lines hidden (view full) ---

797 have -= copy;
798 next += copy;
799 if (len) goto inf_leave;
800 }
801 else if (state->head != Z_NULL)
802 state->head->name = Z_NULL;
803 state->length = 0;
804 state->mode = COMMENT;
805 /* fallthrough */
799 case COMMENT:
800 if (state->flags & 0x1000) {
801 if (have == 0) goto inf_leave;
802 copy = 0;
803 do {
804 len = (unsigned)(next[copy++]);
805 if (state->head != Z_NULL &&
806 state->head->comment != Z_NULL &&

--- 4 unchanged lines hidden (view full) ---

811 state->check = crc32(state->check, next, copy);
812 have -= copy;
813 next += copy;
814 if (len) goto inf_leave;
815 }
816 else if (state->head != Z_NULL)
817 state->head->comment = Z_NULL;
818 state->mode = HCRC;
806 case COMMENT:
807 if (state->flags & 0x1000) {
808 if (have == 0) goto inf_leave;
809 copy = 0;
810 do {
811 len = (unsigned)(next[copy++]);
812 if (state->head != Z_NULL &&
813 state->head->comment != Z_NULL &&

--- 4 unchanged lines hidden (view full) ---

818 state->check = crc32(state->check, next, copy);
819 have -= copy;
820 next += copy;
821 if (len) goto inf_leave;
822 }
823 else if (state->head != Z_NULL)
824 state->head->comment = Z_NULL;
825 state->mode = HCRC;
826 /* fallthrough */
819 case HCRC:
820 if (state->flags & 0x0200) {
821 NEEDBITS(16);
822 if ((state->wrap & 4) && hold != (state->check & 0xffff)) {
823 strm->msg = (char *)"header crc mismatch";
824 state->mode = BAD;
825 break;
826 }

--- 7 unchanged lines hidden (view full) ---

834 state->mode = TYPE;
835 break;
836#endif
837 case DICTID:
838 NEEDBITS(32);
839 strm->adler = state->check = ZSWAP32(hold);
840 INITBITS();
841 state->mode = DICT;
827 case HCRC:
828 if (state->flags & 0x0200) {
829 NEEDBITS(16);
830 if ((state->wrap & 4) && hold != (state->check & 0xffff)) {
831 strm->msg = (char *)"header crc mismatch";
832 state->mode = BAD;
833 break;
834 }

--- 7 unchanged lines hidden (view full) ---

842 state->mode = TYPE;
843 break;
844#endif
845 case DICTID:
846 NEEDBITS(32);
847 strm->adler = state->check = ZSWAP32(hold);
848 INITBITS();
849 state->mode = DICT;
850 /* fallthrough */
842 case DICT:
843 if (state->havedict == 0) {
844 RESTORE();
845 return Z_NEED_DICT;
846 }
847 strm->adler = state->check = adler32(0L, Z_NULL, 0);
848 state->mode = TYPE;
851 case DICT:
852 if (state->havedict == 0) {
853 RESTORE();
854 return Z_NEED_DICT;
855 }
856 strm->adler = state->check = adler32(0L, Z_NULL, 0);
857 state->mode = TYPE;
858 /* fallthrough */
849 case TYPE:
850 if (flush == Z_BLOCK || flush == Z_TREES) goto inf_leave;
859 case TYPE:
860 if (flush == Z_BLOCK || flush == Z_TREES) goto inf_leave;
861 /* fallthrough */
851 case TYPEDO:
852 if (state->last) {
853 BYTEBITS();
854 state->mode = CHECK;
855 break;
856 }
857 NEEDBITS(3);
858 state->last = BITS(1);

--- 34 unchanged lines hidden (view full) ---

893 break;
894 }
895 state->length = (unsigned)hold & 0xffff;
896 Tracev((stderr, "inflate: stored length %u\n",
897 state->length));
898 INITBITS();
899 state->mode = COPY_;
900 if (flush == Z_TREES) goto inf_leave;
862 case TYPEDO:
863 if (state->last) {
864 BYTEBITS();
865 state->mode = CHECK;
866 break;
867 }
868 NEEDBITS(3);
869 state->last = BITS(1);

--- 34 unchanged lines hidden (view full) ---

904 break;
905 }
906 state->length = (unsigned)hold & 0xffff;
907 Tracev((stderr, "inflate: stored length %u\n",
908 state->length));
909 INITBITS();
910 state->mode = COPY_;
911 if (flush == Z_TREES) goto inf_leave;
912 /* fallthrough */
901 case COPY_:
902 state->mode = COPY;
913 case COPY_:
914 state->mode = COPY;
915 /* fallthrough */
903 case COPY:
904 copy = state->length;
905 if (copy) {
906 if (copy > have) copy = have;
907 if (copy > left) copy = left;
908 if (copy == 0) goto inf_leave;
909 zmemcpy(put, next, copy);
910 have -= copy;

--- 19 unchanged lines hidden (view full) ---

930 strm->msg = (char *)"too many length or distance symbols";
931 state->mode = BAD;
932 break;
933 }
934#endif
935 Tracev((stderr, "inflate: table sizes ok\n"));
936 state->have = 0;
937 state->mode = LENLENS;
916 case COPY:
917 copy = state->length;
918 if (copy) {
919 if (copy > have) copy = have;
920 if (copy > left) copy = left;
921 if (copy == 0) goto inf_leave;
922 zmemcpy(put, next, copy);
923 have -= copy;

--- 19 unchanged lines hidden (view full) ---

943 strm->msg = (char *)"too many length or distance symbols";
944 state->mode = BAD;
945 break;
946 }
947#endif
948 Tracev((stderr, "inflate: table sizes ok\n"));
949 state->have = 0;
950 state->mode = LENLENS;
951 /* fallthrough */
938 case LENLENS:
939 while (state->have < state->ncode) {
940 NEEDBITS(3);
941 state->lens[order[state->have++]] = (unsigned short)BITS(3);
942 DROPBITS(3);
943 }
944 while (state->have < 19)
945 state->lens[order[state->have++]] = 0;

--- 5 unchanged lines hidden (view full) ---

951 if (ret) {
952 strm->msg = (char *)"invalid code lengths set";
953 state->mode = BAD;
954 break;
955 }
956 Tracev((stderr, "inflate: code lengths ok\n"));
957 state->have = 0;
958 state->mode = CODELENS;
952 case LENLENS:
953 while (state->have < state->ncode) {
954 NEEDBITS(3);
955 state->lens[order[state->have++]] = (unsigned short)BITS(3);
956 DROPBITS(3);
957 }
958 while (state->have < 19)
959 state->lens[order[state->have++]] = 0;

--- 5 unchanged lines hidden (view full) ---

965 if (ret) {
966 strm->msg = (char *)"invalid code lengths set";
967 state->mode = BAD;
968 break;
969 }
970 Tracev((stderr, "inflate: code lengths ok\n"));
971 state->have = 0;
972 state->mode = CODELENS;
973 /* fallthrough */
959 case CODELENS:
960 while (state->have < state->nlen + state->ndist) {
961 for (;;) {
962 here = state->lencode[BITS(state->lenbits)];
963 if ((unsigned)(here.bits) <= bits) break;
964 PULLBYTE();
965 }
966 if (here.val < 16) {

--- 67 unchanged lines hidden (view full) ---

1034 if (ret) {
1035 strm->msg = (char *)"invalid distances set";
1036 state->mode = BAD;
1037 break;
1038 }
1039 Tracev((stderr, "inflate: codes ok\n"));
1040 state->mode = LEN_;
1041 if (flush == Z_TREES) goto inf_leave;
974 case CODELENS:
975 while (state->have < state->nlen + state->ndist) {
976 for (;;) {
977 here = state->lencode[BITS(state->lenbits)];
978 if ((unsigned)(here.bits) <= bits) break;
979 PULLBYTE();
980 }
981 if (here.val < 16) {

--- 67 unchanged lines hidden (view full) ---

1049 if (ret) {
1050 strm->msg = (char *)"invalid distances set";
1051 state->mode = BAD;
1052 break;
1053 }
1054 Tracev((stderr, "inflate: codes ok\n"));
1055 state->mode = LEN_;
1056 if (flush == Z_TREES) goto inf_leave;
1057 /* fallthrough */
1042 case LEN_:
1043 state->mode = LEN;
1058 case LEN_:
1059 state->mode = LEN;
1060 /* fallthrough */
1044 case LEN:
1045 if (have >= 6 && left >= 258) {
1046 RESTORE();
1047 inflate_fast(strm, out);
1048 LOAD();
1049 if (state->mode == TYPE)
1050 state->back = -1;
1051 break;

--- 33 unchanged lines hidden (view full) ---

1085 }
1086 if (here.op & 64) {
1087 strm->msg = (char *)"invalid literal/length code";
1088 state->mode = BAD;
1089 break;
1090 }
1091 state->extra = (unsigned)(here.op) & 15;
1092 state->mode = LENEXT;
1061 case LEN:
1062 if (have >= 6 && left >= 258) {
1063 RESTORE();
1064 inflate_fast(strm, out);
1065 LOAD();
1066 if (state->mode == TYPE)
1067 state->back = -1;
1068 break;

--- 33 unchanged lines hidden (view full) ---

1102 }
1103 if (here.op & 64) {
1104 strm->msg = (char *)"invalid literal/length code";
1105 state->mode = BAD;
1106 break;
1107 }
1108 state->extra = (unsigned)(here.op) & 15;
1109 state->mode = LENEXT;
1110 /* fallthrough */
1093 case LENEXT:
1094 if (state->extra) {
1095 NEEDBITS(state->extra);
1096 state->length += BITS(state->extra);
1097 DROPBITS(state->extra);
1098 state->back += state->extra;
1099 }
1100 Tracevv((stderr, "inflate: length %u\n", state->length));
1101 state->was = state->length;
1102 state->mode = DIST;
1111 case LENEXT:
1112 if (state->extra) {
1113 NEEDBITS(state->extra);
1114 state->length += BITS(state->extra);
1115 DROPBITS(state->extra);
1116 state->back += state->extra;
1117 }
1118 Tracevv((stderr, "inflate: length %u\n", state->length));
1119 state->was = state->length;
1120 state->mode = DIST;
1121 /* fallthrough */
1103 case DIST:
1104 for (;;) {
1105 here = state->distcode[BITS(state->distbits)];
1106 if ((unsigned)(here.bits) <= bits) break;
1107 PULLBYTE();
1108 }
1109 if ((here.op & 0xf0) == 0) {
1110 last = here;

--- 11 unchanged lines hidden (view full) ---

1122 if (here.op & 64) {
1123 strm->msg = (char *)"invalid distance code";
1124 state->mode = BAD;
1125 break;
1126 }
1127 state->offset = (unsigned)here.val;
1128 state->extra = (unsigned)(here.op) & 15;
1129 state->mode = DISTEXT;
1122 case DIST:
1123 for (;;) {
1124 here = state->distcode[BITS(state->distbits)];
1125 if ((unsigned)(here.bits) <= bits) break;
1126 PULLBYTE();
1127 }
1128 if ((here.op & 0xf0) == 0) {
1129 last = here;

--- 11 unchanged lines hidden (view full) ---

1141 if (here.op & 64) {
1142 strm->msg = (char *)"invalid distance code";
1143 state->mode = BAD;
1144 break;
1145 }
1146 state->offset = (unsigned)here.val;
1147 state->extra = (unsigned)(here.op) & 15;
1148 state->mode = DISTEXT;
1149 /* fallthrough */
1130 case DISTEXT:
1131 if (state->extra) {
1132 NEEDBITS(state->extra);
1133 state->offset += BITS(state->extra);
1134 DROPBITS(state->extra);
1135 state->back += state->extra;
1136 }
1137#ifdef INFLATE_STRICT
1138 if (state->offset > state->dmax) {
1139 strm->msg = (char *)"invalid distance too far back";
1140 state->mode = BAD;
1141 break;
1142 }
1143#endif
1144 Tracevv((stderr, "inflate: distance %u\n", state->offset));
1145 state->mode = MATCH;
1150 case DISTEXT:
1151 if (state->extra) {
1152 NEEDBITS(state->extra);
1153 state->offset += BITS(state->extra);
1154 DROPBITS(state->extra);
1155 state->back += state->extra;
1156 }
1157#ifdef INFLATE_STRICT
1158 if (state->offset > state->dmax) {
1159 strm->msg = (char *)"invalid distance too far back";
1160 state->mode = BAD;
1161 break;
1162 }
1163#endif
1164 Tracevv((stderr, "inflate: distance %u\n", state->offset));
1165 state->mode = MATCH;
1166 /* fallthrough */
1146 case MATCH:
1147 if (left == 0) goto inf_leave;
1148 copy = out - left;
1149 if (state->offset > copy) { /* copy from window */
1150 copy = state->offset - copy;
1151 if (copy > state->whave) {
1152 if (state->sane) {
1153 strm->msg = (char *)"invalid distance too far back";

--- 43 unchanged lines hidden (view full) ---

1197 case CHECK:
1198 if (state->wrap) {
1199 NEEDBITS(32);
1200 out -= left;
1201 strm->total_out += out;
1202 state->total += out;
1203 if ((state->wrap & 4) && out)
1204 strm->adler = state->check =
1167 case MATCH:
1168 if (left == 0) goto inf_leave;
1169 copy = out - left;
1170 if (state->offset > copy) { /* copy from window */
1171 copy = state->offset - copy;
1172 if (copy > state->whave) {
1173 if (state->sane) {
1174 strm->msg = (char *)"invalid distance too far back";

--- 43 unchanged lines hidden (view full) ---

1218 case CHECK:
1219 if (state->wrap) {
1220 NEEDBITS(32);
1221 out -= left;
1222 strm->total_out += out;
1223 state->total += out;
1224 if ((state->wrap & 4) && out)
1225 strm->adler = state->check =
1205 UPDATE(state->check, put - out, out);
1226 UPDATE_CHECK(state->check, put - out, out);
1206 out = left;
1207 if ((state->wrap & 4) && (
1208#ifdef GUNZIP
1209 state->flags ? hold :
1210#endif
1211 ZSWAP32(hold)) != state->check) {
1212 strm->msg = (char *)"incorrect data check";
1213 state->mode = BAD;
1214 break;
1215 }
1216 INITBITS();
1217 Tracev((stderr, "inflate: check matches trailer\n"));
1218 }
1219#ifdef GUNZIP
1220 state->mode = LENGTH;
1227 out = left;
1228 if ((state->wrap & 4) && (
1229#ifdef GUNZIP
1230 state->flags ? hold :
1231#endif
1232 ZSWAP32(hold)) != state->check) {
1233 strm->msg = (char *)"incorrect data check";
1234 state->mode = BAD;
1235 break;
1236 }
1237 INITBITS();
1238 Tracev((stderr, "inflate: check matches trailer\n"));
1239 }
1240#ifdef GUNZIP
1241 state->mode = LENGTH;
1242 /* fallthrough */
1221 case LENGTH:
1222 if (state->wrap && state->flags) {
1223 NEEDBITS(32);
1243 case LENGTH:
1244 if (state->wrap && state->flags) {
1245 NEEDBITS(32);
1224 if (hold != (state->total & 0xffffffffUL)) {
1246 if ((state->wrap & 4) && hold != (state->total & 0xffffffff)) {
1225 strm->msg = (char *)"incorrect length check";
1226 state->mode = BAD;
1227 break;
1228 }
1229 INITBITS();
1230 Tracev((stderr, "inflate: length matches trailer\n"));
1231 }
1232#endif
1233 state->mode = DONE;
1247 strm->msg = (char *)"incorrect length check";
1248 state->mode = BAD;
1249 break;
1250 }
1251 INITBITS();
1252 Tracev((stderr, "inflate: length matches trailer\n"));
1253 }
1254#endif
1255 state->mode = DONE;
1256 /* fallthrough */
1234 case DONE:
1235 ret = Z_STREAM_END;
1236 goto inf_leave;
1237 case BAD:
1238 ret = Z_DATA_ERROR;
1239 goto inf_leave;
1240 case MEM:
1241 return Z_MEM_ERROR;
1242 case SYNC:
1257 case DONE:
1258 ret = Z_STREAM_END;
1259 goto inf_leave;
1260 case BAD:
1261 ret = Z_DATA_ERROR;
1262 goto inf_leave;
1263 case MEM:
1264 return Z_MEM_ERROR;
1265 case SYNC:
1266 /* fallthrough */
1243 default:
1244 return Z_STREAM_ERROR;
1245 }
1246
1247 /*
1248 Return from inflate(), updating the total counts and the check value.
1249 If there was no progress during the inflate() call, return a buffer
1250 error. Call updatewindow() to create and/or update the window state.

--- 9 unchanged lines hidden (view full) ---

1260 }
1261 in -= strm->avail_in;
1262 out -= strm->avail_out;
1263 strm->total_in += in;
1264 strm->total_out += out;
1265 state->total += out;
1266 if ((state->wrap & 4) && out)
1267 strm->adler = state->check =
1267 default:
1268 return Z_STREAM_ERROR;
1269 }
1270
1271 /*
1272 Return from inflate(), updating the total counts and the check value.
1273 If there was no progress during the inflate() call, return a buffer
1274 error. Call updatewindow() to create and/or update the window state.

--- 9 unchanged lines hidden (view full) ---

1284 }
1285 in -= strm->avail_in;
1286 out -= strm->avail_out;
1287 strm->total_in += in;
1288 strm->total_out += out;
1289 state->total += out;
1290 if ((state->wrap & 4) && out)
1291 strm->adler = state->check =
1268 UPDATE(state->check, strm->next_out - out, out);
1292 UPDATE_CHECK(state->check, strm->next_out - out, out);
1269 strm->data_type = (int)state->bits + (state->last ? 64 : 0) +
1270 (state->mode == TYPE ? 128 : 0) +
1271 (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0);
1272 if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
1273 ret = Z_BUF_ERROR;
1274 return ret;
1275}
1276

--- 119 unchanged lines hidden (view full) ---

1396 *have = got;
1397 return next;
1398}
1399
1400int ZEXPORT inflateSync(strm)
1401z_streamp strm;
1402{
1403 unsigned len; /* number of bytes to look at or looked at */
1293 strm->data_type = (int)state->bits + (state->last ? 64 : 0) +
1294 (state->mode == TYPE ? 128 : 0) +
1295 (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0);
1296 if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
1297 ret = Z_BUF_ERROR;
1298 return ret;
1299}
1300

--- 119 unchanged lines hidden (view full) ---

1420 *have = got;
1421 return next;
1422}
1423
1424int ZEXPORT inflateSync(strm)
1425z_streamp strm;
1426{
1427 unsigned len; /* number of bytes to look at or looked at */
1428 int flags; /* temporary to save header status */
1404 unsigned long in, out; /* temporary to save total_in and total_out */
1405 unsigned char buf[4]; /* to restore bit buffer to byte string */
1406 struct inflate_state FAR *state;
1407
1408 /* check parameters */
1409 if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
1410 state = (struct inflate_state FAR *)strm->state;
1411 if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;

--- 16 unchanged lines hidden (view full) ---

1428 /* search available input */
1429 len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
1430 strm->avail_in -= len;
1431 strm->next_in += len;
1432 strm->total_in += len;
1433
1434 /* return no joy or set up to restart inflate() on a new block */
1435 if (state->have != 4) return Z_DATA_ERROR;
1429 unsigned long in, out; /* temporary to save total_in and total_out */
1430 unsigned char buf[4]; /* to restore bit buffer to byte string */
1431 struct inflate_state FAR *state;
1432
1433 /* check parameters */
1434 if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
1435 state = (struct inflate_state FAR *)strm->state;
1436 if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;

--- 16 unchanged lines hidden (view full) ---

1453 /* search available input */
1454 len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
1455 strm->avail_in -= len;
1456 strm->next_in += len;
1457 strm->total_in += len;
1458
1459 /* return no joy or set up to restart inflate() on a new block */
1460 if (state->have != 4) return Z_DATA_ERROR;
1461 if (state->flags == -1)
1462 state->wrap = 0; /* if no header yet, treat as raw */
1463 else
1464 state->wrap &= ~4; /* no point in computing a check value now */
1465 flags = state->flags;
1436 in = strm->total_in; out = strm->total_out;
1437 inflateReset(strm);
1438 strm->total_in = in; strm->total_out = out;
1466 in = strm->total_in; out = strm->total_out;
1467 inflateReset(strm);
1468 strm->total_in = in; strm->total_out = out;
1469 state->flags = flags;
1439 state->mode = TYPE;
1440 return Z_OK;
1441}
1442
1443/*
1444 Returns true if inflate is currently at the end of a block generated by
1445 Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
1446 implementation to provide an additional safety check. PPP uses

--- 79 unchanged lines hidden (view full) ---

1526int ZEXPORT inflateValidate(strm, check)
1527z_streamp strm;
1528int check;
1529{
1530 struct inflate_state FAR *state;
1531
1532 if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
1533 state = (struct inflate_state FAR *)strm->state;
1470 state->mode = TYPE;
1471 return Z_OK;
1472}
1473
1474/*
1475 Returns true if inflate is currently at the end of a block generated by
1476 Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
1477 implementation to provide an additional safety check. PPP uses

--- 79 unchanged lines hidden (view full) ---

1557int ZEXPORT inflateValidate(strm, check)
1558z_streamp strm;
1559int check;
1560{
1561 struct inflate_state FAR *state;
1562
1563 if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
1564 state = (struct inflate_state FAR *)strm->state;
1534 if (check)
1565 if (check && state->wrap)
1535 state->wrap |= 4;
1536 else
1537 state->wrap &= ~4;
1538 return Z_OK;
1539}
1540
1541long ZEXPORT inflateMark(strm)
1542z_streamp strm;

--- 19 unchanged lines hidden ---
1566 state->wrap |= 4;
1567 else
1568 state->wrap &= ~4;
1569 return Z_OK;
1570}
1571
1572long ZEXPORT inflateMark(strm)
1573z_streamp strm;

--- 19 unchanged lines hidden ---