diff options
author | Mark Adler <madler@alumni.caltech.edu> | 2016-11-22 23:29:19 -0800 |
---|---|---|
committer | Mark Adler <madler@alumni.caltech.edu> | 2016-12-04 07:48:47 -0800 |
commit | 7161ad76e2d0ac7de2a6235fcad3b9dfc99e9140 (patch) | |
tree | c549e902ffc2e63b4ad12e2e60a8868c0e0573aa | |
parent | 1101ea79c65c6f42c33a1e3a5d5eef38c00a30a2 (diff) | |
download | zlib-7161ad76e2d0ac7de2a6235fcad3b9dfc99e9140.tar.gz zlib-7161ad76e2d0ac7de2a6235fcad3b9dfc99e9140.tar.bz2 zlib-7161ad76e2d0ac7de2a6235fcad3b9dfc99e9140.zip |
Assure that deflateParams() will not switch functions mid-block.
This alters the specification in zlib.h, so that deflateParams()
will not change any parameters if there is not enough output space
in the event that a block is emitted in order to allow switching
the compression function.
-rw-r--r-- | deflate.c | 11 | ||||
-rw-r--r-- | zlib.h | 35 |
2 files changed, 24 insertions, 22 deletions
@@ -517,7 +517,6 @@ int ZEXPORT deflateParams(strm, level, strategy) | |||
517 | { | 517 | { |
518 | deflate_state *s; | 518 | deflate_state *s; |
519 | compress_func func; | 519 | compress_func func; |
520 | int err = Z_OK; | ||
521 | 520 | ||
522 | if (deflateStateCheck(strm)) return Z_STREAM_ERROR; | 521 | if (deflateStateCheck(strm)) return Z_STREAM_ERROR; |
523 | s = strm->state; | 522 | s = strm->state; |
@@ -534,9 +533,11 @@ int ZEXPORT deflateParams(strm, level, strategy) | |||
534 | 533 | ||
535 | if ((strategy != s->strategy || func != configuration_table[level].func)) { | 534 | if ((strategy != s->strategy || func != configuration_table[level].func)) { |
536 | /* Flush the last buffer: */ | 535 | /* Flush the last buffer: */ |
537 | err = deflate(strm, Z_BLOCK); | 536 | int err = deflate(strm, Z_BLOCK); |
538 | if (err == Z_BUF_ERROR && s->pending == 0) | 537 | if (err == Z_STREAM_ERROR) |
539 | err = Z_OK; | 538 | return err; |
539 | if (strm->avail_out == 0) | ||
540 | return Z_BUF_ERROR; | ||
540 | } | 541 | } |
541 | if (s->level != level) { | 542 | if (s->level != level) { |
542 | s->level = level; | 543 | s->level = level; |
@@ -546,7 +547,7 @@ int ZEXPORT deflateParams(strm, level, strategy) | |||
546 | s->max_chain_length = configuration_table[level].max_chain; | 547 | s->max_chain_length = configuration_table[level].max_chain; |
547 | } | 548 | } |
548 | s->strategy = strategy; | 549 | s->strategy = strategy; |
549 | return err; | 550 | return Z_OK; |
550 | } | 551 | } |
551 | 552 | ||
552 | /* ========================================================================= */ | 553 | /* ========================================================================= */ |
@@ -695,24 +695,25 @@ ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, | |||
695 | new level and strategy will take effect at the next call of deflate(). | 695 | new level and strategy will take effect at the next call of deflate(). |
696 | 696 | ||
697 | If a deflate(strm, Z_BLOCK) is performed by deflateParams(), and it does | 697 | If a deflate(strm, Z_BLOCK) is performed by deflateParams(), and it does |
698 | not have enough output space to complete, then the parameter change will | 698 | not have enough output space to complete, then the parameter change will not |
699 | take effect at an undetermined location in the uncompressed data provided so | 699 | take effect. In this case, deflateParams() can be called again with the |
700 | far. In order to assure a change in the parameters at a specific location | 700 | same parameters and more output space to try again. |
701 | in the uncompressed data, the deflate stream should first be flushed with | 701 | |
702 | Z_BLOCK or another flush parameter, and deflate() called until | 702 | In order to assure a change in the parameters on the first try, the |
703 | strm.avail_out is not zero, before the call of deflateParams(). Then no | 703 | deflate stream should be flushed using deflate() with Z_BLOCK or other flush |
704 | more input data should be provided before the deflateParams() call. If this | 704 | request until strm.avail_out is not zero, before calling deflateParams(). |
705 | is done, the old level and strategy will be applied to the data compressed | 705 | Then no more input data should be provided before the deflateParams() call. |
706 | before deflateParams(), and the new level and strategy will be applied to | 706 | If this is done, the old level and strategy will be applied to the data |
707 | the the data compressed after deflateParams(). | 707 | compressed before deflateParams(), and the new level and strategy will be |
708 | 708 | applied to the the data compressed after deflateParams(). | |
709 | deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source stream | 709 | |
710 | deflateParams returns Z_OK on success, Z_STREAM_ERROR if the source stream | ||
710 | state was inconsistent or if a parameter was invalid, or Z_BUF_ERROR if | 711 | state was inconsistent or if a parameter was invalid, or Z_BUF_ERROR if |
711 | there was not enough output space to complete the compression before the | 712 | there was not enough output space to complete the compression of the |
712 | parameters were changed. Note that in the case of a Z_BUF_ERROR, the | 713 | available input data before a change in the strategy or approach. Note that |
713 | parameters are changed nevertheless, and will take effect at an undetermined | 714 | in the case of a Z_BUF_ERROR, the parameters are not changed. A return |
714 | location in the previously supplied uncompressed data. Compression may | 715 | value of Z_BUF_ERROR is not fatal, in which case deflateParams() can be |
715 | proceed after a Z_BUF_ERROR. | 716 | retried with more output space. |
716 | */ | 717 | */ |
717 | 718 | ||
718 | ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, | 719 | ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, |