diff options
Diffstat (limited to 'infcodes.c')
-rw-r--r-- | infcodes.c | 81 |
1 files changed, 41 insertions, 40 deletions
@@ -83,7 +83,7 @@ int r; | |||
83 | { | 83 | { |
84 | uInt j; /* temporary storage */ | 84 | uInt j; /* temporary storage */ |
85 | inflate_huft *t; /* temporary pointer */ | 85 | inflate_huft *t; /* temporary pointer */ |
86 | int e; /* extra bits or operation */ | 86 | uInt e; /* extra bits or operation */ |
87 | uLong b; /* bit buffer */ | 87 | uLong b; /* bit buffer */ |
88 | uInt k; /* bits in bit buffer */ | 88 | uInt k; /* bits in bit buffer */ |
89 | Byte *p; /* input data pointer */ | 89 | Byte *p; /* input data pointer */ |
@@ -91,7 +91,7 @@ int r; | |||
91 | Byte *q; /* output window write pointer */ | 91 | Byte *q; /* output window write pointer */ |
92 | uInt m; /* bytes to end of window or read pointer */ | 92 | uInt m; /* bytes to end of window or read pointer */ |
93 | Byte *f; /* pointer to copy strings from */ | 93 | Byte *f; /* pointer to copy strings from */ |
94 | struct inflate_codes_state *c = s->sub.codes; /* codes state */ | 94 | struct inflate_codes_state *c = s->sub.decode.codes; /* codes state */ |
95 | 95 | ||
96 | /* copy input/output information to locals (UPDATE macro restores) */ | 96 | /* copy input/output information to locals (UPDATE macro restores) */ |
97 | LOAD | 97 | LOAD |
@@ -121,27 +121,8 @@ int r; | |||
121 | NEEDBITS(j) | 121 | NEEDBITS(j) |
122 | t = c->sub.code.tree + ((uInt)b & inflate_mask[j]); | 122 | t = c->sub.code.tree + ((uInt)b & inflate_mask[j]); |
123 | DUMPBITS(t->bits) | 123 | DUMPBITS(t->bits) |
124 | if ((e = (int)(t->exop)) < 0) | 124 | e = (uInt)(t->exop); |
125 | { | 125 | if (e == 0) /* literal */ |
126 | if (e == -128) /* invalid code */ | ||
127 | { | ||
128 | c->mode = BADCODE; | ||
129 | z->msg = "invalid literal/length code"; | ||
130 | r = Z_DATA_ERROR; | ||
131 | LEAVE | ||
132 | } | ||
133 | e = -e; | ||
134 | if (e & 64) /* end of block */ | ||
135 | { | ||
136 | Tracevv((stderr, "inflate: end of block\n")); | ||
137 | c->mode = WASH; | ||
138 | break; | ||
139 | } | ||
140 | c->sub.code.need = e; | ||
141 | c->sub.code.tree = t->next; | ||
142 | break; | ||
143 | } | ||
144 | if (e & 16) /* literal */ | ||
145 | { | 126 | { |
146 | c->sub.lit = t->base; | 127 | c->sub.lit = t->base; |
147 | Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ? | 128 | Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ? |
@@ -150,9 +131,29 @@ int r; | |||
150 | c->mode = LIT; | 131 | c->mode = LIT; |
151 | break; | 132 | break; |
152 | } | 133 | } |
153 | c->sub.copy.get = e; | 134 | if (e & 16) /* length */ |
154 | c->len = t->base; | 135 | { |
155 | c->mode = LENEXT; | 136 | c->sub.copy.get = e & 15; |
137 | c->len = t->base; | ||
138 | c->mode = LENEXT; | ||
139 | break; | ||
140 | } | ||
141 | if ((e & 64) == 0) /* next table */ | ||
142 | { | ||
143 | c->sub.code.need = e; | ||
144 | c->sub.code.tree = t->next; | ||
145 | break; | ||
146 | } | ||
147 | if (e & 32) /* end of block */ | ||
148 | { | ||
149 | Tracevv((stderr, "inflate: end of block\n")); | ||
150 | c->mode = WASH; | ||
151 | break; | ||
152 | } | ||
153 | c->mode = BADCODE; /* invalid code */ | ||
154 | z->msg = "invalid literal/length code"; | ||
155 | r = Z_DATA_ERROR; | ||
156 | LEAVE | ||
156 | case LENEXT: /* i: getting length extra (have base) */ | 157 | case LENEXT: /* i: getting length extra (have base) */ |
157 | j = c->sub.copy.get; | 158 | j = c->sub.copy.get; |
158 | NEEDBITS(j) | 159 | NEEDBITS(j) |
@@ -167,22 +168,24 @@ int r; | |||
167 | NEEDBITS(j) | 168 | NEEDBITS(j) |
168 | t = c->sub.code.tree + ((uInt)b & inflate_mask[j]); | 169 | t = c->sub.code.tree + ((uInt)b & inflate_mask[j]); |
169 | DUMPBITS(t->bits) | 170 | DUMPBITS(t->bits) |
170 | if ((e = (int)(t->exop)) < 0) | 171 | e = (uInt)(t->exop); |
172 | if (e & 16) /* distance */ | ||
171 | { | 173 | { |
172 | if (e == -128) | 174 | c->sub.copy.get = e & 15; |
173 | { | 175 | c->sub.copy.dist = t->base; |
174 | c->mode = BADCODE; | 176 | c->mode = DISTEXT; |
175 | z->msg = "invalid distance code"; | 177 | break; |
176 | r = Z_DATA_ERROR; | 178 | } |
177 | LEAVE | 179 | if ((e & 64) == 0) /* next table */ |
178 | } | 180 | { |
179 | c->sub.code.need = -e; | 181 | c->sub.code.need = e; |
180 | c->sub.code.tree = t->next; | 182 | c->sub.code.tree = t->next; |
181 | break; | 183 | break; |
182 | } | 184 | } |
183 | c->sub.copy.dist = t->base; | 185 | c->mode = BADCODE; /* invalid code */ |
184 | c->sub.copy.get = e; | 186 | z->msg = "invalid distance code"; |
185 | c->mode = DISTEXT; | 187 | r = Z_DATA_ERROR; |
188 | LEAVE | ||
186 | case DISTEXT: /* i: getting distance extra */ | 189 | case DISTEXT: /* i: getting distance extra */ |
187 | j = c->sub.copy.get; | 190 | j = c->sub.copy.get; |
188 | NEEDBITS(j) | 191 | NEEDBITS(j) |
@@ -231,8 +234,6 @@ void inflate_codes_free(c, z) | |||
231 | struct inflate_codes_state *c; | 234 | struct inflate_codes_state *c; |
232 | z_stream *z; | 235 | z_stream *z; |
233 | { | 236 | { |
234 | inflate_trees_free(c->dtree, z); | ||
235 | inflate_trees_free(c->ltree, z); | ||
236 | ZFREE(z, c); | 237 | ZFREE(z, c); |
237 | Tracev((stderr, "inflate: codes free\n")); | 238 | Tracev((stderr, "inflate: codes free\n")); |
238 | } | 239 | } |