diff options
-rw-r--r-- | deflate.c | 59 | ||||
-rw-r--r-- | inflate.c | 51 | ||||
-rw-r--r-- | inflate.h | 3 |
3 files changed, 72 insertions, 41 deletions
@@ -73,6 +73,7 @@ typedef enum { | |||
73 | typedef block_state (*compress_func) OF((deflate_state *s, int flush)); | 73 | typedef block_state (*compress_func) OF((deflate_state *s, int flush)); |
74 | /* Compression function. Returns the block state after the call. */ | 74 | /* Compression function. Returns the block state after the call. */ |
75 | 75 | ||
76 | local int deflateStateCheck OF((z_streamp strm)); | ||
76 | local void fill_window OF((deflate_state *s)); | 77 | local void fill_window OF((deflate_state *s)); |
77 | local block_state deflate_stored OF((deflate_state *s, int flush)); | 78 | local block_state deflate_stored OF((deflate_state *s, int flush)); |
78 | local block_state deflate_fast OF((deflate_state *s, int flush)); | 79 | local block_state deflate_fast OF((deflate_state *s, int flush)); |
@@ -271,6 +272,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, | |||
271 | if (s == Z_NULL) return Z_MEM_ERROR; | 272 | if (s == Z_NULL) return Z_MEM_ERROR; |
272 | strm->state = (struct internal_state FAR *)s; | 273 | strm->state = (struct internal_state FAR *)s; |
273 | s->strm = strm; | 274 | s->strm = strm; |
275 | s->status = INIT_STATE; /* to pass state test in deflateReset() */ | ||
274 | 276 | ||
275 | s->wrap = wrap; | 277 | s->wrap = wrap; |
276 | s->gzhead = Z_NULL; | 278 | s->gzhead = Z_NULL; |
@@ -312,6 +314,28 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, | |||
312 | return deflateReset(strm); | 314 | return deflateReset(strm); |
313 | } | 315 | } |
314 | 316 | ||
317 | /* ========================================================================= | ||
318 | * Check for a valid deflate stream state. Return 0 if ok, 1 if not. | ||
319 | */ | ||
320 | local int deflateStateCheck (strm) | ||
321 | z_streamp strm; | ||
322 | { | ||
323 | deflate_state *s; | ||
324 | if (strm == Z_NULL || | ||
325 | strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) | ||
326 | return 1; | ||
327 | s = strm->state; | ||
328 | if (s == Z_NULL || s->strm != strm || (s->status != INIT_STATE && | ||
329 | s->status != EXTRA_STATE && | ||
330 | s->status != NAME_STATE && | ||
331 | s->status != COMMENT_STATE && | ||
332 | s->status != HCRC_STATE && | ||
333 | s->status != BUSY_STATE && | ||
334 | s->status != FINISH_STATE)) | ||
335 | return 1; | ||
336 | return 0; | ||
337 | } | ||
338 | |||
315 | /* ========================================================================= */ | 339 | /* ========================================================================= */ |
316 | int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength) | 340 | int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength) |
317 | z_streamp strm; | 341 | z_streamp strm; |
@@ -324,7 +348,7 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength) | |||
324 | unsigned avail; | 348 | unsigned avail; |
325 | z_const unsigned char *next; | 349 | z_const unsigned char *next; |
326 | 350 | ||
327 | if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL) | 351 | if (deflateStateCheck(strm) || dictionary == Z_NULL) |
328 | return Z_STREAM_ERROR; | 352 | return Z_STREAM_ERROR; |
329 | s = strm->state; | 353 | s = strm->state; |
330 | wrap = s->wrap; | 354 | wrap = s->wrap; |
@@ -387,8 +411,7 @@ int ZEXPORT deflateResetKeep (strm) | |||
387 | { | 411 | { |
388 | deflate_state *s; | 412 | deflate_state *s; |
389 | 413 | ||
390 | if (strm == Z_NULL || strm->state == Z_NULL || | 414 | if (deflateStateCheck(strm)) { |
391 | strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) { | ||
392 | return Z_STREAM_ERROR; | 415 | return Z_STREAM_ERROR; |
393 | } | 416 | } |
394 | 417 | ||
@@ -433,8 +456,8 @@ int ZEXPORT deflateSetHeader (strm, head) | |||
433 | z_streamp strm; | 456 | z_streamp strm; |
434 | gz_headerp head; | 457 | gz_headerp head; |
435 | { | 458 | { |
436 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | 459 | if (deflateStateCheck(strm) || strm->state->wrap != 2) |
437 | if (strm->state->wrap != 2) return Z_STREAM_ERROR; | 460 | return Z_STREAM_ERROR; |
438 | strm->state->gzhead = head; | 461 | strm->state->gzhead = head; |
439 | return Z_OK; | 462 | return Z_OK; |
440 | } | 463 | } |
@@ -445,7 +468,7 @@ int ZEXPORT deflatePending (strm, pending, bits) | |||
445 | int *bits; | 468 | int *bits; |
446 | z_streamp strm; | 469 | z_streamp strm; |
447 | { | 470 | { |
448 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | 471 | if (deflateStateCheck(strm)) return Z_STREAM_ERROR; |
449 | if (pending != Z_NULL) | 472 | if (pending != Z_NULL) |
450 | *pending = strm->state->pending; | 473 | *pending = strm->state->pending; |
451 | if (bits != Z_NULL) | 474 | if (bits != Z_NULL) |
@@ -462,7 +485,7 @@ int ZEXPORT deflatePrime (strm, bits, value) | |||
462 | deflate_state *s; | 485 | deflate_state *s; |
463 | int put; | 486 | int put; |
464 | 487 | ||
465 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | 488 | if (deflateStateCheck(strm)) return Z_STREAM_ERROR; |
466 | s = strm->state; | 489 | s = strm->state; |
467 | if ((Bytef *)(s->d_buf) < s->pending_out + ((Buf_size + 7) >> 3)) | 490 | if ((Bytef *)(s->d_buf) < s->pending_out + ((Buf_size + 7) >> 3)) |
468 | return Z_BUF_ERROR; | 491 | return Z_BUF_ERROR; |
@@ -489,7 +512,7 @@ int ZEXPORT deflateParams(strm, level, strategy) | |||
489 | compress_func func; | 512 | compress_func func; |
490 | int err = Z_OK; | 513 | int err = Z_OK; |
491 | 514 | ||
492 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | 515 | if (deflateStateCheck(strm)) return Z_STREAM_ERROR; |
493 | s = strm->state; | 516 | s = strm->state; |
494 | 517 | ||
495 | #ifdef FASTEST | 518 | #ifdef FASTEST |
@@ -529,7 +552,7 @@ int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain) | |||
529 | { | 552 | { |
530 | deflate_state *s; | 553 | deflate_state *s; |
531 | 554 | ||
532 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | 555 | if (deflateStateCheck(strm)) return Z_STREAM_ERROR; |
533 | s = strm->state; | 556 | s = strm->state; |
534 | s->good_match = (uInt)good_length; | 557 | s->good_match = (uInt)good_length; |
535 | s->max_lazy_match = (uInt)max_lazy; | 558 | s->max_lazy_match = (uInt)max_lazy; |
@@ -568,7 +591,7 @@ uLong ZEXPORT deflateBound(strm, sourceLen) | |||
568 | ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5; | 591 | ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5; |
569 | 592 | ||
570 | /* if can't get parameters, return conservative bound plus zlib wrapper */ | 593 | /* if can't get parameters, return conservative bound plus zlib wrapper */ |
571 | if (strm == Z_NULL || strm->state == Z_NULL) | 594 | if (deflateStateCheck(strm)) |
572 | return complen + 6; | 595 | return complen + 6; |
573 | 596 | ||
574 | /* compute wrapper length */ | 597 | /* compute wrapper length */ |
@@ -661,8 +684,7 @@ int ZEXPORT deflate (strm, flush) | |||
661 | int old_flush; /* value of flush param for previous deflate call */ | 684 | int old_flush; /* value of flush param for previous deflate call */ |
662 | deflate_state *s; | 685 | deflate_state *s; |
663 | 686 | ||
664 | if (strm == Z_NULL || strm->state == Z_NULL || | 687 | if (deflateStateCheck(strm) || flush > Z_BLOCK || flush < 0) { |
665 | flush > Z_BLOCK || flush < 0) { | ||
666 | return Z_STREAM_ERROR; | 688 | return Z_STREAM_ERROR; |
667 | } | 689 | } |
668 | s = strm->state; | 690 | s = strm->state; |
@@ -973,18 +995,9 @@ int ZEXPORT deflateEnd (strm) | |||
973 | { | 995 | { |
974 | int status; | 996 | int status; |
975 | 997 | ||
976 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | 998 | if (deflateStateCheck(strm)) return Z_STREAM_ERROR; |
977 | 999 | ||
978 | status = strm->state->status; | 1000 | status = strm->state->status; |
979 | if (status != INIT_STATE && | ||
980 | status != EXTRA_STATE && | ||
981 | status != NAME_STATE && | ||
982 | status != COMMENT_STATE && | ||
983 | status != HCRC_STATE && | ||
984 | status != BUSY_STATE && | ||
985 | status != FINISH_STATE) { | ||
986 | return Z_STREAM_ERROR; | ||
987 | } | ||
988 | 1001 | ||
989 | /* Deallocate in reverse order of allocations: */ | 1002 | /* Deallocate in reverse order of allocations: */ |
990 | TRY_FREE(strm, strm->state->pending_buf); | 1003 | TRY_FREE(strm, strm->state->pending_buf); |
@@ -1015,7 +1028,7 @@ int ZEXPORT deflateCopy (dest, source) | |||
1015 | ushf *overlay; | 1028 | ushf *overlay; |
1016 | 1029 | ||
1017 | 1030 | ||
1018 | if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) { | 1031 | if (deflateStateCheck(source) || dest == Z_NULL) { |
1019 | return Z_STREAM_ERROR; | 1032 | return Z_STREAM_ERROR; |
1020 | } | 1033 | } |
1021 | 1034 | ||
@@ -92,6 +92,7 @@ | |||
92 | #endif | 92 | #endif |
93 | 93 | ||
94 | /* function prototypes */ | 94 | /* function prototypes */ |
95 | local int inflateStateCheck OF((z_streamp strm)); | ||
95 | local void fixedtables OF((struct inflate_state FAR *state)); | 96 | local void fixedtables OF((struct inflate_state FAR *state)); |
96 | local int updatewindow OF((z_streamp strm, const unsigned char FAR *end, | 97 | local int updatewindow OF((z_streamp strm, const unsigned char FAR *end, |
97 | unsigned copy)); | 98 | unsigned copy)); |
@@ -101,12 +102,26 @@ local int updatewindow OF((z_streamp strm, const unsigned char FAR *end, | |||
101 | local unsigned syncsearch OF((unsigned FAR *have, const unsigned char FAR *buf, | 102 | local unsigned syncsearch OF((unsigned FAR *have, const unsigned char FAR *buf, |
102 | unsigned len)); | 103 | unsigned len)); |
103 | 104 | ||
105 | local int inflateStateCheck(strm) | ||
106 | z_streamp strm; | ||
107 | { | ||
108 | struct inflate_state FAR *state; | ||
109 | if (strm == Z_NULL || | ||
110 | strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) | ||
111 | return 1; | ||
112 | state = (struct inflate_state FAR *)strm->state; | ||
113 | if (state == Z_NULL || state->strm != strm || | ||
114 | state->mode < HEAD || state->mode > SYNC) | ||
115 | return 1; | ||
116 | return 0; | ||
117 | } | ||
118 | |||
104 | int ZEXPORT inflateResetKeep(strm) | 119 | int ZEXPORT inflateResetKeep(strm) |
105 | z_streamp strm; | 120 | z_streamp strm; |
106 | { | 121 | { |
107 | struct inflate_state FAR *state; | 122 | struct inflate_state FAR *state; |
108 | 123 | ||
109 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | 124 | if (inflateStateCheck(strm)) return Z_STREAM_ERROR; |
110 | state = (struct inflate_state FAR *)strm->state; | 125 | state = (struct inflate_state FAR *)strm->state; |
111 | strm->total_in = strm->total_out = state->total = 0; | 126 | strm->total_in = strm->total_out = state->total = 0; |
112 | strm->msg = Z_NULL; | 127 | strm->msg = Z_NULL; |
@@ -131,7 +146,7 @@ z_streamp strm; | |||
131 | { | 146 | { |
132 | struct inflate_state FAR *state; | 147 | struct inflate_state FAR *state; |
133 | 148 | ||
134 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | 149 | if (inflateStateCheck(strm)) return Z_STREAM_ERROR; |
135 | state = (struct inflate_state FAR *)strm->state; | 150 | state = (struct inflate_state FAR *)strm->state; |
136 | state->wsize = 0; | 151 | state->wsize = 0; |
137 | state->whave = 0; | 152 | state->whave = 0; |
@@ -147,7 +162,7 @@ int windowBits; | |||
147 | struct inflate_state FAR *state; | 162 | struct inflate_state FAR *state; |
148 | 163 | ||
149 | /* get the state */ | 164 | /* get the state */ |
150 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | 165 | if (inflateStateCheck(strm)) return Z_STREAM_ERROR; |
151 | state = (struct inflate_state FAR *)strm->state; | 166 | state = (struct inflate_state FAR *)strm->state; |
152 | 167 | ||
153 | /* extract wrap request from windowBits parameter */ | 168 | /* extract wrap request from windowBits parameter */ |
@@ -210,7 +225,9 @@ int stream_size; | |||
210 | if (state == Z_NULL) return Z_MEM_ERROR; | 225 | if (state == Z_NULL) return Z_MEM_ERROR; |
211 | Tracev((stderr, "inflate: allocated\n")); | 226 | Tracev((stderr, "inflate: allocated\n")); |
212 | strm->state = (struct internal_state FAR *)state; | 227 | strm->state = (struct internal_state FAR *)state; |
228 | state->strm = strm; | ||
213 | state->window = Z_NULL; | 229 | state->window = Z_NULL; |
230 | state->mode = HEAD; /* to pass state test in inflateReset2() */ | ||
214 | ret = inflateReset2(strm, windowBits); | 231 | ret = inflateReset2(strm, windowBits); |
215 | if (ret != Z_OK) { | 232 | if (ret != Z_OK) { |
216 | ZFREE(strm, state); | 233 | ZFREE(strm, state); |
@@ -234,7 +251,7 @@ int value; | |||
234 | { | 251 | { |
235 | struct inflate_state FAR *state; | 252 | struct inflate_state FAR *state; |
236 | 253 | ||
237 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | 254 | if (inflateStateCheck(strm)) return Z_STREAM_ERROR; |
238 | state = (struct inflate_state FAR *)strm->state; | 255 | state = (struct inflate_state FAR *)strm->state; |
239 | if (bits < 0) { | 256 | if (bits < 0) { |
240 | state->hold = 0; | 257 | state->hold = 0; |
@@ -625,7 +642,7 @@ int flush; | |||
625 | static const unsigned short order[19] = /* permutation of code lengths */ | 642 | static const unsigned short order[19] = /* permutation of code lengths */ |
626 | {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; | 643 | {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; |
627 | 644 | ||
628 | if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL || | 645 | if (inflateStateCheck(strm) || strm->next_out == Z_NULL || |
629 | (strm->next_in == Z_NULL && strm->avail_in != 0)) | 646 | (strm->next_in == Z_NULL && strm->avail_in != 0)) |
630 | return Z_STREAM_ERROR; | 647 | return Z_STREAM_ERROR; |
631 | 648 | ||
@@ -1261,7 +1278,7 @@ int ZEXPORT inflateEnd(strm) | |||
1261 | z_streamp strm; | 1278 | z_streamp strm; |
1262 | { | 1279 | { |
1263 | struct inflate_state FAR *state; | 1280 | struct inflate_state FAR *state; |
1264 | if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) | 1281 | if (inflateStateCheck(strm)) |
1265 | return Z_STREAM_ERROR; | 1282 | return Z_STREAM_ERROR; |
1266 | state = (struct inflate_state FAR *)strm->state; | 1283 | state = (struct inflate_state FAR *)strm->state; |
1267 | if (state->window != Z_NULL) ZFREE(strm, state->window); | 1284 | if (state->window != Z_NULL) ZFREE(strm, state->window); |
@@ -1279,7 +1296,7 @@ uInt *dictLength; | |||
1279 | struct inflate_state FAR *state; | 1296 | struct inflate_state FAR *state; |
1280 | 1297 | ||
1281 | /* check state */ | 1298 | /* check state */ |
1282 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | 1299 | if (inflateStateCheck(strm)) return Z_STREAM_ERROR; |
1283 | state = (struct inflate_state FAR *)strm->state; | 1300 | state = (struct inflate_state FAR *)strm->state; |
1284 | 1301 | ||
1285 | /* copy dictionary */ | 1302 | /* copy dictionary */ |
@@ -1304,7 +1321,7 @@ uInt dictLength; | |||
1304 | int ret; | 1321 | int ret; |
1305 | 1322 | ||
1306 | /* check state */ | 1323 | /* check state */ |
1307 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | 1324 | if (inflateStateCheck(strm)) return Z_STREAM_ERROR; |
1308 | state = (struct inflate_state FAR *)strm->state; | 1325 | state = (struct inflate_state FAR *)strm->state; |
1309 | if (state->wrap != 0 && state->mode != DICT) | 1326 | if (state->wrap != 0 && state->mode != DICT) |
1310 | return Z_STREAM_ERROR; | 1327 | return Z_STREAM_ERROR; |
@@ -1336,7 +1353,7 @@ gz_headerp head; | |||
1336 | struct inflate_state FAR *state; | 1353 | struct inflate_state FAR *state; |
1337 | 1354 | ||
1338 | /* check state */ | 1355 | /* check state */ |
1339 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | 1356 | if (inflateStateCheck(strm)) return Z_STREAM_ERROR; |
1340 | state = (struct inflate_state FAR *)strm->state; | 1357 | state = (struct inflate_state FAR *)strm->state; |
1341 | if ((state->wrap & 2) == 0) return Z_STREAM_ERROR; | 1358 | if ((state->wrap & 2) == 0) return Z_STREAM_ERROR; |
1342 | 1359 | ||
@@ -1389,7 +1406,7 @@ z_streamp strm; | |||
1389 | struct inflate_state FAR *state; | 1406 | struct inflate_state FAR *state; |
1390 | 1407 | ||
1391 | /* check parameters */ | 1408 | /* check parameters */ |
1392 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | 1409 | if (inflateStateCheck(strm)) return Z_STREAM_ERROR; |
1393 | state = (struct inflate_state FAR *)strm->state; | 1410 | state = (struct inflate_state FAR *)strm->state; |
1394 | if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR; | 1411 | if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR; |
1395 | 1412 | ||
@@ -1436,7 +1453,7 @@ z_streamp strm; | |||
1436 | { | 1453 | { |
1437 | struct inflate_state FAR *state; | 1454 | struct inflate_state FAR *state; |
1438 | 1455 | ||
1439 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | 1456 | if (inflateStateCheck(strm)) return Z_STREAM_ERROR; |
1440 | state = (struct inflate_state FAR *)strm->state; | 1457 | state = (struct inflate_state FAR *)strm->state; |
1441 | return state->mode == STORED && state->bits == 0; | 1458 | return state->mode == STORED && state->bits == 0; |
1442 | } | 1459 | } |
@@ -1451,8 +1468,7 @@ z_streamp source; | |||
1451 | unsigned wsize; | 1468 | unsigned wsize; |
1452 | 1469 | ||
1453 | /* check input */ | 1470 | /* check input */ |
1454 | if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL || | 1471 | if (inflateStateCheck(source) || dest == Z_NULL) |
1455 | source->zalloc == (alloc_func)0 || source->zfree == (free_func)0) | ||
1456 | return Z_STREAM_ERROR; | 1472 | return Z_STREAM_ERROR; |
1457 | state = (struct inflate_state FAR *)source->state; | 1473 | state = (struct inflate_state FAR *)source->state; |
1458 | 1474 | ||
@@ -1473,6 +1489,7 @@ z_streamp source; | |||
1473 | /* copy state */ | 1489 | /* copy state */ |
1474 | zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream)); | 1490 | zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream)); |
1475 | zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state)); | 1491 | zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state)); |
1492 | copy->strm = dest; | ||
1476 | if (state->lencode >= state->codes && | 1493 | if (state->lencode >= state->codes && |
1477 | state->lencode <= state->codes + ENOUGH - 1) { | 1494 | state->lencode <= state->codes + ENOUGH - 1) { |
1478 | copy->lencode = copy->codes + (state->lencode - state->codes); | 1495 | copy->lencode = copy->codes + (state->lencode - state->codes); |
@@ -1494,7 +1511,7 @@ int subvert; | |||
1494 | { | 1511 | { |
1495 | struct inflate_state FAR *state; | 1512 | struct inflate_state FAR *state; |
1496 | 1513 | ||
1497 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | 1514 | if (inflateStateCheck(strm)) return Z_STREAM_ERROR; |
1498 | state = (struct inflate_state FAR *)strm->state; | 1515 | state = (struct inflate_state FAR *)strm->state; |
1499 | #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR | 1516 | #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR |
1500 | state->sane = !subvert; | 1517 | state->sane = !subvert; |
@@ -1512,7 +1529,7 @@ int check; | |||
1512 | { | 1529 | { |
1513 | struct inflate_state FAR *state; | 1530 | struct inflate_state FAR *state; |
1514 | 1531 | ||
1515 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | 1532 | if (inflateStateCheck(strm)) return Z_STREAM_ERROR; |
1516 | state = (struct inflate_state FAR *)strm->state; | 1533 | state = (struct inflate_state FAR *)strm->state; |
1517 | if (check) | 1534 | if (check) |
1518 | state->wrap |= 4; | 1535 | state->wrap |= 4; |
@@ -1526,7 +1543,7 @@ z_streamp strm; | |||
1526 | { | 1543 | { |
1527 | struct inflate_state FAR *state; | 1544 | struct inflate_state FAR *state; |
1528 | 1545 | ||
1529 | if (strm == Z_NULL || strm->state == Z_NULL) | 1546 | if (inflateStateCheck(strm)) |
1530 | return -(1L << 16); | 1547 | return -(1L << 16); |
1531 | state = (struct inflate_state FAR *)strm->state; | 1548 | state = (struct inflate_state FAR *)strm->state; |
1532 | return (long)(((unsigned long)((long)state->back)) << 16) + | 1549 | return (long)(((unsigned long)((long)state->back)) << 16) + |
@@ -1538,7 +1555,7 @@ unsigned long ZEXPORT inflateCodesUsed(strm) | |||
1538 | z_streamp strm; | 1555 | z_streamp strm; |
1539 | { | 1556 | { |
1540 | struct inflate_state FAR *state; | 1557 | struct inflate_state FAR *state; |
1541 | if (strm == Z_NULL || strm->state == Z_NULL) return (unsigned long)0 - 1; | 1558 | if (inflateStateCheck(strm)) return (unsigned long)0 - 1; |
1542 | state = (struct inflate_state FAR *)strm->state; | 1559 | state = (struct inflate_state FAR *)strm->state; |
1543 | return (unsigned long)(state->next - state->codes); | 1560 | return (unsigned long)(state->next - state->codes); |
1544 | } | 1561 | } |
@@ -18,7 +18,7 @@ | |||
18 | 18 | ||
19 | /* Possible inflate modes between inflate() calls */ | 19 | /* Possible inflate modes between inflate() calls */ |
20 | typedef enum { | 20 | typedef enum { |
21 | HEAD, /* i: waiting for magic header */ | 21 | HEAD = 16180, /* i: waiting for magic header */ |
22 | FLAGS, /* i: waiting for method and flags (gzip) */ | 22 | FLAGS, /* i: waiting for method and flags (gzip) */ |
23 | TIME, /* i: waiting for modification time (gzip) */ | 23 | TIME, /* i: waiting for modification time (gzip) */ |
24 | OS, /* i: waiting for extra flags and operating system (gzip) */ | 24 | OS, /* i: waiting for extra flags and operating system (gzip) */ |
@@ -80,6 +80,7 @@ typedef enum { | |||
80 | /* State maintained between inflate() calls -- approximately 7K bytes, not | 80 | /* State maintained between inflate() calls -- approximately 7K bytes, not |
81 | including the allocated sliding window, which is up to 32K bytes. */ | 81 | including the allocated sliding window, which is up to 32K bytes. */ |
82 | struct inflate_state { | 82 | struct inflate_state { |
83 | z_streamp strm; /* pointer back to this zlib stream */ | ||
83 | inflate_mode mode; /* current inflate mode */ | 84 | inflate_mode mode; /* current inflate mode */ |
84 | int last; /* true if processing last block */ | 85 | int last; /* true if processing last block */ |
85 | int wrap; /* bit 0 true for zlib, bit 1 true for gzip, | 86 | int wrap; /* bit 0 true for zlib, bit 1 true for gzip, |