summaryrefslogtreecommitdiff
path: root/inflate.c
diff options
context:
space:
mode:
Diffstat (limited to 'inflate.c')
-rw-r--r--inflate.c33
1 files changed, 11 insertions, 22 deletions
diff --git a/inflate.c b/inflate.c
index 38d70cc..b76e246 100644
--- a/inflate.c
+++ b/inflate.c
@@ -22,7 +22,7 @@ struct internal_state {
22 CHECK2, /* two check bytes to go */ 22 CHECK2, /* two check bytes to go */
23 CHECK1, /* one check byte to go */ 23 CHECK1, /* one check byte to go */
24 DONE, /* finished check, done */ 24 DONE, /* finished check, done */
25 ERROR} /* got an error--stay here */ 25 INF_ERROR}/* got an error--stay here */
26 mode; /* current inflate mode */ 26 mode; /* current inflate mode */
27 27
28 /* mode dependent information */ 28 /* mode dependent information */
@@ -92,7 +92,7 @@ int inflate(z, f)
92z_stream *z; 92z_stream *z;
93int f; 93int f;
94{ 94{
95 int r; 95 int r = f; /* to avoid warning about unused f */
96 uInt b; 96 uInt b;
97 uLong c; 97 uLong c;
98 98
@@ -105,13 +105,13 @@ int f;
105 if (z->avail_in == 0) return r; r = Z_OK; 105 if (z->avail_in == 0) return r; r = Z_OK;
106 if (((z->state->sub.method = NEXTBYTE) & 0xf != DEFLATED)) 106 if (((z->state->sub.method = NEXTBYTE) & 0xf != DEFLATED))
107 { 107 {
108 z->state->mode = ERROR; 108 z->state->mode = INF_ERROR;
109 z->msg = "unknown compression method"; 109 z->msg = "unknown compression method";
110 return Z_DATA_ERROR; 110 return Z_DATA_ERROR;
111 } 111 }
112 if ((z->state->sub.method >> 4) + 8 > z->state->wbits) 112 if ((z->state->sub.method >> 4) + 8 > z->state->wbits)
113 { 113 {
114 z->state->mode = ERROR; 114 z->state->mode = INF_ERROR;
115 z->msg = "invalid window size"; 115 z->msg = "invalid window size";
116 return Z_DATA_ERROR; 116 return Z_DATA_ERROR;
117 } 117 }
@@ -120,13 +120,13 @@ int f;
120 if (z->avail_in == 0) return r; r = Z_OK; 120 if (z->avail_in == 0) return r; r = Z_OK;
121 if ((b = NEXTBYTE) & 0x20) 121 if ((b = NEXTBYTE) & 0x20)
122 { 122 {
123 z->state->mode = ERROR; 123 z->state->mode = INF_ERROR;
124 z->msg = "invalid reserved bit"; 124 z->msg = "invalid reserved bit";
125 return Z_DATA_ERROR; 125 return Z_DATA_ERROR;
126 } 126 }
127 if (((z->state->sub.method << 8) + b) % 31) 127 if (((z->state->sub.method << 8) + b) % 31)
128 { 128 {
129 z->state->mode = ERROR; 129 z->state->mode = INF_ERROR;
130 z->msg = "incorrect header check"; 130 z->msg = "incorrect header check";
131 return Z_DATA_ERROR; 131 return Z_DATA_ERROR;
132 } 132 }
@@ -140,23 +140,13 @@ int f;
140 case BLOCKS: 140 case BLOCKS:
141 if ((r = inflate_blocks(z->state->sub.blocks, z, r)) != Z_STREAM_END) 141 if ((r = inflate_blocks(z->state->sub.blocks, z, r)) != Z_STREAM_END)
142 return r; 142 return r;
143 inflate_blocks_free(z->state->sub.blocks, z, &c, &r); 143 inflate_blocks_free(z->state->sub.blocks, z, &c);
144 if (z->state->nowrap) 144 if (z->state->nowrap)
145 { 145 {
146 if (r != -1) 146 z->state->mode = DONE;
147 z->msg = "inflate bug--took one too many bytes";
148 z->state->mode = r == -1 ? DONE : ERROR;
149 break; 147 break;
150 } 148 }
151 z->state->sub.check.was = c; 149 z->state->sub.check.was = c;
152 if (r != -1)
153 {
154 z->state->sub.check.need = (uLong)r << 24;
155 z->state->mode = CHECK3;
156 r = Z_OK;
157 break;
158 }
159 r = Z_OK;
160 z->state->mode = CHECK4; 150 z->state->mode = CHECK4;
161 case CHECK4: 151 case CHECK4:
162 if (z->avail_in == 0) return r; r = Z_OK; 152 if (z->avail_in == 0) return r; r = Z_OK;
@@ -175,14 +165,14 @@ int f;
175 z->state->sub.check.need += (uLong)NEXTBYTE; 165 z->state->sub.check.need += (uLong)NEXTBYTE;
176 if (z->state->sub.check.was != z->state->sub.check.need) 166 if (z->state->sub.check.was != z->state->sub.check.need)
177 { 167 {
178 z->state->mode = ERROR; 168 z->state->mode = INF_ERROR;
179 z->msg = "incorrect data check"; 169 z->msg = "incorrect data check";
180 return Z_DATA_ERROR; 170 return Z_DATA_ERROR;
181 } 171 }
182 z->state->mode = DONE; 172 z->state->mode = DONE;
183 case DONE: 173 case DONE:
184 return Z_STREAM_END; 174 return Z_STREAM_END;
185 case ERROR: 175 case INF_ERROR:
186 return Z_DATA_ERROR; 176 return Z_DATA_ERROR;
187 default: 177 default:
188 return Z_STREAM_ERROR; 178 return Z_STREAM_ERROR;
@@ -194,12 +184,11 @@ int inflateEnd(z)
194z_stream *z; 184z_stream *z;
195{ 185{
196 uLong c; 186 uLong c;
197 int e;
198 187
199 if (z == Z_NULL || z->state == Z_NULL || z->zfree == Z_NULL) 188 if (z == Z_NULL || z->state == Z_NULL || z->zfree == Z_NULL)
200 return Z_STREAM_ERROR; 189 return Z_STREAM_ERROR;
201 if (z->state->mode == BLOCKS) 190 if (z->state->mode == BLOCKS)
202 inflate_blocks_free(z->state->sub.blocks, z, &c, &e); 191 inflate_blocks_free(z->state->sub.blocks, z, &c);
203 ZFREE(z, z->state); 192 ZFREE(z, z->state);
204 z->state = Z_NULL; 193 z->state = Z_NULL;
205 return Z_OK; 194 return Z_OK;