adenilson / rpms / zlib

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