adenilson / rpms / zlib

Forked from rpms/zlib 8 months ago
Clone
65fa5e
From d09bb1ab8ef9bb91457c0ead09589e8807489260 Mon Sep 17 00:00:00 2001
65fa5e
From: Ondrej Dubaj <odubaj@redhat.com>
65fa5e
Date: Thu, 6 Aug 2020 08:09:53 +0200
65fa5e
Subject: [PATCH] Permit a deflateParams() parameter change.
65fa5e
65fa5e
This change allows a parameter change even if the input data has
65fa5e
not all been compressed and copied to the application output
65fa5e
buffer, so long as all of the input data has been compressed to
65fa5e
the internal pending output buffer. This also allows an immediate
65fa5e
deflateParams change so long as there have been no deflate calls
65fa5e
since initialization or reset.
65fa5e
---
65fa5e
 deflate.c |  6 +++---
65fa5e
 zlib.h    | 11 ++++++-----
65fa5e
 2 files changed, 9 insertions(+), 8 deletions(-)
65fa5e
65fa5e
diff --git a/deflate.c b/deflate.c
65fa5e
index 9705c1c..f3c9924 100644
65fa5e
--- a/deflate.c
65fa5e
+++ b/deflate.c
65fa5e
@@ -509,7 +509,7 @@ int ZEXPORT deflateResetKeep (strm)
65fa5e
         s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
65fa5e
 #endif
65fa5e
         adler32(0L, Z_NULL, 0);
65fa5e
-    s->last_flush = Z_NO_FLUSH;
65fa5e
+    s->last_flush = -2;
65fa5e
 
65fa5e
     _tr_init(s);
65fa5e
 
65fa5e
@@ -606,13 +606,13 @@ int ZEXPORT deflateParams(strm, level, strategy)
65fa5e
     func = configuration_table[s->level].func;
65fa5e
 
65fa5e
     if ((strategy != s->strategy || func != configuration_table[level].func ||
65fa5e
-        hook_flush != Z_NO_FLUSH) && s->high_water) {
65fa5e
+        hook_flush != Z_NO_FLUSH) && s->last_flush != -2) {
65fa5e
         /* Flush the last buffer: */
65fa5e
         int err = deflate(strm, RANK(hook_flush) > RANK(Z_BLOCK) ?
65fa5e
                           hook_flush : Z_BLOCK); 
65fa5e
         if (err == Z_STREAM_ERROR)
65fa5e
             return err;
65fa5e
-        if (strm->avail_out == 0)
65fa5e
+        if (strm->avail_in || (s->strstart - s->block_start) + s->lookahead)
65fa5e
             return Z_BUF_ERROR;
65fa5e
     }
65fa5e
     if (s->level != level) {
65fa5e
diff --git a/zlib.h b/zlib.h
65fa5e
index f09cdaf..001624e 100644
65fa5e
--- a/zlib.h
65fa5e
+++ b/zlib.h
65fa5e
@@ -712,11 +712,12 @@ ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
65fa5e
    used to switch between compression and straight copy of the input data, or
65fa5e
    to switch to a different kind of input data requiring a different strategy.
65fa5e
    If the compression approach (which is a function of the level) or the
65fa5e
-   strategy is changed, and if any input has been consumed in a previous
65fa5e
-   deflate() call, then the input available so far is compressed with the old
65fa5e
-   level and strategy using deflate(strm, Z_BLOCK).  There are three approaches
65fa5e
-   for the compression levels 0, 1..3, and 4..9 respectively.  The new level
65fa5e
-   and strategy will take effect at the next call of deflate().
65fa5e
+   strategy is changed, and if there have been any deflate() calls since the
65fa5e
+   state was initialized or reset, then the input available so far is
65fa5e
+   compressed with the old level and strategy using deflate(strm, Z_BLOCK).
65fa5e
+   There are three approaches for the compression levels 0, 1..3, and 4..9
65fa5e
+   respectively.  The new level and strategy will take effect at the next call
65fa5e
+   of deflate().
65fa5e
 
65fa5e
      If a deflate(strm, Z_BLOCK) is performed by deflateParams(), and it does
65fa5e
    not have enough output space to complete, then the parameter change will not
65fa5e
-- 
65fa5e
2.26.0
65fa5e