Blob Blame History Raw
From b42f5c088158f473116d3aca2d050d4efb95b021 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
Date: Tue, 7 Feb 2017 14:44:48 +0100
Subject: [PATCH] Adapt tests to zlib 1.2.11
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Since zlib-1.2.9 it's not safe to invoke deflateParams() when not all
input was consumed by deflate(). deflateParams() could return
Z_BUF_ERROR in some cases:

commit 7161ad76e2d0ac7de2a6235fcad3b9dfc99e9140
Author: Mark Adler <madler@alumni.caltech.edu>
Date:   Tue Nov 22 23:29:19 2016 -0800

    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.

zlib documentation recommends two fixes:

To retry deflateParams() as it processes a piece of input underneath
until something else than Z_BUF_ERROR is returned. However this does
not work for me because then the compressed stream gets corrupted
and the subsequent inflate() returns a failure.

Another fix is to flush the deflated stream with Z_BLOCK just before
any deflateParams() call that follows unifinished deflate(). This
assures the new deflate options will be applied immediatelly on next
deflate() call. This fix works for me. Thus I implemented it in the
tests.

The new tests pass with zlib 1.2.8 as well as 1.2.11. 1.2.9 and 1.2.10
seems broken changing the deflate options was fixed in 1.2.11.

CPAN RT#119762

Signed-off-by: Petr Písař <ppisar@redhat.com>
---
 t/02zlib.t | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/t/02zlib.t b/t/02zlib.t
index 2c9aad6..50f6a82 100644
--- a/t/02zlib.t
+++ b/t/02zlib.t
@@ -24,13 +24,13 @@ BEGIN
 
     my $count = 0 ;
     if ($] < 5.005) {
-        $count = 232 ;
+        $count = 236 ;
     }
     elsif ($] >= 5.006) {
-        $count = 317 ;
+        $count = 320 ;
     }
     else {
-        $count = 275 ;
+        $count = 278 ;
     }
 
     plan tests => $count + $extra;
@@ -537,6 +537,7 @@ SKIP:
      
     $status = $x->deflate($hello, $Answer) ;
     cmp_ok $status, '==', Z_OK ;
+    cmp_ok $x->flush($Answer, Z_BLOCK), '==', Z_OK ;
     $input .= $hello;
     
     # error cases
@@ -561,6 +562,7 @@ SKIP:
      
     $status = $x->deflate($goodbye, $Answer) ;
     cmp_ok $status, '==', Z_OK ;
+    cmp_ok $x->flush($Answer, Z_BLOCK), '==', Z_OK ;
     $input .= $goodbye;
     
     # change only Level 
@@ -572,6 +574,7 @@ SKIP:
      
     $status = $x->deflate($goodbye, $Answer) ;
     cmp_ok $status, '==', Z_OK ;
+    cmp_ok $x->flush($Answer, Z_BLOCK), '==', Z_OK ;
     $input .= $goodbye;
     
     # change only Strategy
-- 
2.7.4