61217e9
From b42f5c088158f473116d3aca2d050d4efb95b021 Mon Sep 17 00:00:00 2001
61217e9
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
61217e9
Date: Tue, 7 Feb 2017 14:44:48 +0100
61217e9
Subject: [PATCH] Adapt tests to zlib 1.2.11
61217e9
MIME-Version: 1.0
61217e9
Content-Type: text/plain; charset=UTF-8
61217e9
Content-Transfer-Encoding: 8bit
61217e9
61217e9
Since zlib-1.2.9 it's not safe to invoke deflateParams() when not all
61217e9
input was consumed by deflate(). deflateParams() could return
61217e9
Z_BUF_ERROR in some cases:
61217e9
61217e9
commit 7161ad76e2d0ac7de2a6235fcad3b9dfc99e9140
61217e9
Author: Mark Adler <madler@alumni.caltech.edu>
61217e9
Date:   Tue Nov 22 23:29:19 2016 -0800
61217e9
61217e9
    Assure that deflateParams() will not switch functions mid-block.
61217e9
61217e9
    This alters the specification in zlib.h, so that deflateParams()
61217e9
    will not change any parameters if there is not enough output space
61217e9
    in the event that a block is emitted in order to allow switching
61217e9
    the compression function.
61217e9
61217e9
zlib documentation recommends two fixes:
61217e9
61217e9
To retry deflateParams() as it processes a piece of input underneath
61217e9
until something else than Z_BUF_ERROR is returned. However this does
61217e9
not work for me because then the compressed stream gets corrupted
61217e9
and the subsequent inflate() returns a failure.
61217e9
61217e9
Another fix is to flush the deflated stream with Z_BLOCK just before
61217e9
any deflateParams() call that follows unifinished deflate(). This
61217e9
assures the new deflate options will be applied immediatelly on next
61217e9
deflate() call. This fix works for me. Thus I implemented it in the
61217e9
tests.
61217e9
61217e9
The new tests pass with zlib 1.2.8 as well as 1.2.11. 1.2.9 and 1.2.10
61217e9
seems broken changing the deflate options was fixed in 1.2.11.
61217e9
61217e9
CPAN RT#119762
61217e9
61217e9
Signed-off-by: Petr Písař <ppisar@redhat.com>
61217e9
---
61217e9
 t/02zlib.t | 9 ++++++---
61217e9
 1 file changed, 6 insertions(+), 3 deletions(-)
61217e9
61217e9
diff --git a/t/02zlib.t b/t/02zlib.t
61217e9
index 2c9aad6..50f6a82 100644
61217e9
--- a/t/02zlib.t
61217e9
+++ b/t/02zlib.t
61217e9
@@ -24,13 +24,13 @@ BEGIN
61217e9
 
61217e9
     my $count = 0 ;
61217e9
     if ($] < 5.005) {
61217e9
-        $count = 232 ;
61217e9
+        $count = 236 ;
61217e9
     }
61217e9
     elsif ($] >= 5.006) {
61217e9
-        $count = 317 ;
61217e9
+        $count = 320 ;
61217e9
     }
61217e9
     else {
61217e9
-        $count = 275 ;
61217e9
+        $count = 278 ;
61217e9
     }
61217e9
 
61217e9
     plan tests => $count + $extra;
61217e9
@@ -537,6 +537,7 @@ SKIP:
61217e9
      
61217e9
     $status = $x->deflate($hello, $Answer) ;
61217e9
     cmp_ok $status, '==', Z_OK ;
61217e9
+    cmp_ok $x->flush($Answer, Z_BLOCK), '==', Z_OK ;
61217e9
     $input .= $hello;
61217e9
     
61217e9
     # error cases
61217e9
@@ -561,6 +562,7 @@ SKIP:
61217e9
      
61217e9
     $status = $x->deflate($goodbye, $Answer) ;
61217e9
     cmp_ok $status, '==', Z_OK ;
61217e9
+    cmp_ok $x->flush($Answer, Z_BLOCK), '==', Z_OK ;
61217e9
     $input .= $goodbye;
61217e9
     
61217e9
     # change only Level 
61217e9
@@ -572,6 +574,7 @@ SKIP:
61217e9
      
61217e9
     $status = $x->deflate($goodbye, $Answer) ;
61217e9
     cmp_ok $status, '==', Z_OK ;
61217e9
+    cmp_ok $x->flush($Answer, Z_BLOCK), '==', Z_OK ;
61217e9
     $input .= $goodbye;
61217e9
     
61217e9
     # change only Strategy
61217e9
-- 
61217e9
2.7.4
61217e9