Update Compress-Raw-Zlib to CPAN version 2.064
authorChris 'BinGOs' Williams <chris@bingosnet.co.uk>
Sun, 2 Feb 2014 12:16:43 +0000 (12:16 +0000)
committerChris 'BinGOs' Williams <chris@bingosnet.co.uk>
Sun, 2 Feb 2014 12:16:43 +0000 (12:16 +0000)
  [DELTA]

  2.064 1 February 2014

      * [PATCH] Handle non-PVs better
        [#91558]

      * Z_OK instead of Z_BUF_ERROR
        [#92521]

MANIFEST
Porting/Maintainers.pl
cpan/Compress-Raw-Zlib/Zlib.xs
cpan/Compress-Raw-Zlib/lib/Compress/Raw/Zlib.pm
cpan/Compress-Raw-Zlib/t/09limitoutput.t
cpan/Compress-Raw-Zlib/t/19nonpv.t [new file with mode: 0644]

index 4f47a4f..4664961 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -209,6 +209,7 @@ cpan/Compress-Raw-Zlib/t/02zlib.t           Compress::Raw::Zlib
 cpan/Compress-Raw-Zlib/t/07bufsize.t           Compress::Raw::Zlib
 cpan/Compress-Raw-Zlib/t/09limitoutput.t       Compress::Raw::Zlib
 cpan/Compress-Raw-Zlib/t/18lvalue.t            Compress::Raw::Zlib
+cpan/Compress-Raw-Zlib/t/19nonpv.t
 cpan/Compress-Raw-Zlib/t/compress/CompTestUtils.pm
 cpan/Compress-Raw-Zlib/typemap                 Compress::Raw::Zlib
 cpan/Compress-Raw-Zlib/zlib-src/adler32.c      Compress::Raw::Zlib
index f360768..442a59c 100755 (executable)
@@ -220,7 +220,7 @@ use File::Glob qw(:case);
     },
 
     'Compress::Raw::Zlib' => {
-        'DISTRIBUTION' => 'PMQS/Compress-Raw-Zlib-2.063.tar.gz',
+        'DISTRIBUTION' => 'PMQS/Compress-Raw-Zlib-2.064.tar.gz',
 
         'FILES'    => q[cpan/Compress-Raw-Zlib],
         'EXCLUDED' => [
index 9751a2e..4b2573a 100644 (file)
@@ -77,6 +77,7 @@
 #ifdef USE_PPPORT_H
 #  define NEED_sv_2pvbyte
 #  define NEED_sv_2pv_nolen
+#  define NEED_sv_pvn_force_flags
 #  include "ppport.h"
 #endif
 
@@ -864,13 +865,14 @@ _inflateInit(flags, windowBits, bufsize, dictionary)
             Safefree(s) ;
             s = NULL ;
        }
-       else if (SvCUR(dictionary)) {
+       else if (sv_len(dictionary)) {
 #ifdef AT_LEAST_ZLIB_1_2_2_1
         /* Zlib 1.2.2.1 or better allows a dictionary with raw inflate */
         if (s->WindowBits < 0) {
+            STRLEN dlen;
+            const Bytef* b = (const Bytef*)SvPVbyte(dictionary, dlen);
             err = inflateSetDictionary(&(s->stream), 
-                (const Bytef*)SvPVbyte_nolen(dictionary),
-                SvCUR(dictionary));
+                b, dlen);
             if (err != Z_OK) {
                 Safefree(s) ;
                 s = NULL ;
@@ -938,6 +940,7 @@ deflate (s, buf, output)
     uInt       prefix    = NO_INIT
     int                RETVAL = 0;
     uLong     bufinc = NO_INIT
+    STRLEN    origlen = NO_INIT
   CODE:
     bufinc = s->bufsize;
 
@@ -949,8 +952,8 @@ deflate (s, buf, output)
     if (DO_UTF8(buf) && !sv_utf8_downgrade(buf, 1))
          croak("Wide character in Compress::Raw::Zlib::Deflate::deflate input parameter");
 #endif         
-    s->stream.next_in = (Bytef*)SvPV_nomg_nolen(buf) ;
-    s->stream.avail_in = SvCUR(buf) ;
+    s->stream.next_in = (Bytef*)SvPV_nomg(buf, origlen) ;
+    s->stream.avail_in = origlen;
     
     if (s->flags & FLAG_CRC32)
         s->crc32 = crc32(s->crc32, s->stream.next_in, s->stream.avail_in) ;
@@ -1033,7 +1036,7 @@ deflate (s, buf, output)
     }
 
     s->compressedBytes += cur_length + increment - prefix - s->stream.avail_out ;
-    s->uncompressedBytes  += SvCUR(buf) - s->stream.avail_in  ;
+    s->uncompressedBytes  += origlen - s->stream.avail_in  ;
 
     s->last_error = RETVAL ;
     if (RETVAL == Z_OK) {
@@ -1365,6 +1368,7 @@ inflate (s, buf, output, eof=FALSE)
 #ifdef UTF8_AVAILABLE    
     bool       out_utf8  = FALSE;
 #endif    
+    STRLEN     origlen;
   CODE: 
     bufinc = s->bufsize;
     /* If the buffer is a reference, dereference it */
@@ -1381,8 +1385,8 @@ inflate (s, buf, output, eof=FALSE)
 #endif         
     
     /* initialise the input buffer */
-    s->stream.next_in = (Bytef*)SvPV_nomg_nolen(buf) ;
-    s->stream.avail_in = SvCUR(buf) ;
+    s->stream.next_in = (Bytef*)SvPV_nomg(buf, origlen) ;
+    s->stream.avail_in = origlen ;
        
     /* and retrieve the output buffer */
     output = deRef_l(output, "inflate") ;
@@ -1445,15 +1449,22 @@ Perl_sv_dump(output); */
 
     
         if (RETVAL == Z_NEED_DICT && s->dictionary) {
+            STRLEN dlen;
+            const Bytef* b = SvPV(s->dictionary, dlen) ;
             s->dict_adler = s->stream.adler ;
             RETVAL = inflateSetDictionary(&(s->stream), 
-            (const Bytef*)SvPVX(s->dictionary),
-            SvCUR(s->dictionary));
+                b, dlen);
             if (RETVAL == Z_OK)
                 continue;
         }
         
         if (s->flags & FLAG_LIMIT_OUTPUT && 
+                (RETVAL == Z_OK || RETVAL == Z_BUF_ERROR )) {
+            if (s->stream.avail_out == 0)
+                RETVAL = Z_BUF_ERROR;
+            break;
+        }
+        if (s->flags & FLAG_LIMIT_OUTPUT && 
                 (RETVAL == Z_OK || RETVAL == Z_BUF_ERROR ))
             break;
 
@@ -1497,7 +1508,7 @@ Perl_sv_dump(output); */
 
         s->bytesInflated = cur_length + increment - s->stream.avail_out - prefix_length;
         s->uncompressedBytes += s->bytesInflated ;
-        s->compressedBytes   += SvCUR(buf) - s->stream.avail_in  ;
+        s->compressedBytes   += origlen - s->stream.avail_in  ;
 
         SvPOK_only(output);
         SvCUR_set(output, prefix_length + s->bytesInflated) ;
@@ -1571,7 +1582,7 @@ inflateSync (s, buf)
 #endif         
     
     /* initialise the input buffer */
-    s->stream.next_in = (Bytef*)SvPV_nomg_nolen(buf) ;
+    s->stream.next_in = (Bytef*)SvPV_force_nomg_nolen(buf) ;
     s->stream.avail_in = SvCUR(buf) ;
        
     /* inflateSync doesn't create any output */
index 0c5366a..11d12bc 100644 (file)
@@ -8,9 +8,9 @@ use Carp ;
 use strict ;
 use warnings ;
 use bytes ;
-our ($VERSION, $XS_VERSION, @ISA, @EXPORT, %EXPORT_TAGS, @EXPORT_OK, $AUTOLOAD, %DEFLATE_CONSTANTS, @DEFLATE_CONSTANTS );
+our ($VERSION, $XS_VERSION, @ISA, @EXPORT, %EXPORT_TAGS, @EXPORT_OK, $AUTOLOAD, %DEFLATE_CONSTANTS, @DEFLATE_CONSTANTS);
 
-$VERSION = '2.063';
+$VERSION = '2.064';
 $XS_VERSION = $VERSION; 
 $VERSION = eval $VERSION;
 
@@ -635,8 +635,8 @@ Compress::Raw::Zlib - Low-Level Interface to zlib compression library
     $crc = adler32($buffer [,$crc]) ;
     $crc = crc32($buffer [,$crc]) ;
 
-    $crc = adler32_combine($crc1, $crc2, $len2)l
-    $crc = crc32_combine($adler1, $adler2, $len2)
+    $crc = crc32_combine($crc1, $crc2, $len2);
+    $adler = adler32_combine($adler1, $adler2, $len2);
 
     my $version = Compress::Raw::Zlib::zlib_version();
     my $flags = Compress::Raw::Zlib::zlibCompileFlags();
@@ -1290,10 +1290,11 @@ If the $crc parameters is C<undef>, the crc value will be reset.
 If you have built this module with zlib 1.2.3 or better, two more
 CRC-related functions are available.
 
-    $crc = adler32_combine($crc1, $crc2, $len2)l
-    $crc = crc32_combine($adler1, $adler2, $len2)
+    $crc = crc32_combine($crc1, $crc2, $len2);
+    $adler = adler32_combine($adler1, $adler2, $len2);
 
 These functions allow checksums to be merged.
+Refer to the I<zlib> documentation for more details.
 
 =head1 Misc
 
@@ -1589,7 +1590,7 @@ See the Changes file.
 
 =head1 COPYRIGHT AND LICENSE
 
-Copyright (c) 2005-2013 Paul Marquess. All rights reserved.
+Copyright (c) 2005-2014 Paul Marquess. All rights reserved.
 
 This program is free software; you can redistribute it and/or
 modify it under the same terms as Perl itself.
index a98b18f..2532f9c 100644 (file)
@@ -20,7 +20,7 @@ BEGIN
     $extra = 1
         if eval { require Test::NoWarnings ;  import Test::NoWarnings; 1 };
 
-    plan tests => 98 + $extra ;
+    plan tests => 107 + $extra ;
 
     use_ok('Compress::Raw::Zlib', 2) ; 
 }
@@ -127,3 +127,33 @@ sub getit
                                               
 }
 
+{
+    title "regression test for #92521: Z_OK instead of Z_BUF_ERROR";
+    
+    # 1M "aaa..." 
+    my $in = 'a' x 100000; 
+    my ($deflate, $err) = Compress::Raw::Zlib::Deflate->new(WindowBits => -15, 
+        MemLevel => 8); 
+    ok $deflate ;
+    cmp_ok $err, '==', Z_OK, "  status is Z_OK" ;
+
+    my $status = $deflate->deflate($in, my $zip); 
+    cmp_ok $status, '==', Z_OK, "  status is Z_OK" ;
+
+    cmp_ok $deflate->flush($zip, Z_SYNC_FLUSH), "==", Z_OK; 
+
+    # Compression should stop after 10K "aaa..." with Z_BUF_ERROR 
+    my $inflate;
+    ($inflate, $err)  = Compress::Raw::Zlib::Inflate->new( Bufsize => 10000, 
+        LimitOutput => 1, WindowBits => -15 ); 
+    ok $inflate ;
+    cmp_ok $err, '==', Z_OK, "  status is Z_OK" ;
+
+    $status = $inflate->inflate($zip, my $out); 
+
+    cmp_ok length($out), ">=", 10000;
+    #warn 'RESULT: ', length($out), ' of ', length($in), "\n"; 
+    cmp_ok $status, '==', Z_BUF_ERROR, "  status is Z_BUF_ERROR" ;
+
+}
+
diff --git a/cpan/Compress-Raw-Zlib/t/19nonpv.t b/cpan/Compress-Raw-Zlib/t/19nonpv.t
new file mode 100644 (file)
index 0000000..bbc20c7
--- /dev/null
@@ -0,0 +1,135 @@
+BEGIN {
+    if ($ENV{PERL_CORE}) {
+       chdir 't' if -d 't';
+       @INC = ("../lib", "lib/compress");
+    }
+}
+
+use lib qw(t t/compress);
+use strict;
+use warnings;
+
+use Test::More ;
+use CompTestUtils;
+
+BEGIN 
+{ 
+    # use Test::NoWarnings, if available
+    my $extra = 0 ;
+    $extra = 1
+        if eval { require Test::NoWarnings ;  import Test::NoWarnings; 1 };
+
+    plan tests => 38 + $extra ;
+
+    use_ok('Compress::Raw::Zlib', 2) ;
+}
+
+
+my $hello = <<EOM ;
+hello world
+this is a test
+EOM
+
+my $len   = length $hello ;
+
+# Check zlib_version and ZLIB_VERSION are the same.
+SKIP: {
+    skip "TEST_SKIP_VERSION_CHECK is set", 1 
+        if $ENV{TEST_SKIP_VERSION_CHECK};
+    is Compress::Raw::Zlib::zlib_version, ZLIB_VERSION,
+        "ZLIB_VERSION matches Compress::Raw::Zlib::zlib_version" ;
+}
+
+
+{
+    title 'non-PV dictionary';
+    # ==============================
+
+    my $dictionary = *hello ;
+
+    ok my $x = new Compress::Raw::Zlib::Deflate({-Level => Z_BEST_COMPRESSION,
+                            -Dictionary => $dictionary}) ;
+    my $dictID = $x->dict_adler() ;
+
+    my ($X, $Y, $Z);
+    cmp_ok $x->deflate($hello, $X), '==', Z_OK;
+    cmp_ok $x->flush($Y), '==', Z_OK;
+    $X .= $Y ;
+    ok my $k = new Compress::Raw::Zlib::Inflate(-Dictionary => $dictionary) ;
+    cmp_ok $k->inflate($X, $Z), '==', Z_STREAM_END;
+    is $k->dict_adler(), $dictID;
+    is $hello, $Z ;
+
+}
+
+{
+
+    title  "deflate/inflate - non-PV buffers";
+    # ==============================
+
+    my $hello = *hello ;
+    my ($err, $x, $X, $status); 
+    ok( ($x, $err) = new Compress::Raw::Zlib::Deflate, "Create deflate object" );
+    ok $x, "Compress::Raw::Zlib::Deflate ok" ;
+    cmp_ok $err, '==', Z_OK, "status is Z_OK" ;
+    ok ! defined $x->msg() ;
+    is $x->total_in(), 0, "total_in() == 0" ;
+    is $x->total_out(), 0, "total_out() == 0" ;
+
+    $X = *X;
+    my $Answer = '';
+    $status = $x->deflate($hello, $X) ;
+    $Answer .= $X ;
+     
+    cmp_ok $status, '==', Z_OK, "deflate returned Z_OK" ;
+    
+    $X = *X;
+    cmp_ok  $x->flush($X), '==', Z_OK, "flush returned Z_OK" ;
+    $Answer .= $X ;
+     
+    ok ! defined $x->msg()  ;
+    is $x->total_in(), length $hello, "total_in ok" ;
+    is $x->total_out(), length $Answer, "total_out ok" ;
+     
+    my $k;
+    ok(($k, $err) = new Compress::Raw::Zlib::Inflate);
+    ok $k, "Compress::Raw::Zlib::Inflate ok" ;
+    cmp_ok $err, '==', Z_OK, "status is Z_OK" ;
+    ok ! defined $k->msg(), "No error messages" ;
+    is $k->total_in(), 0, "total_in() == 0" ;
+    is $k->total_out(), 0, "total_out() == 0" ;
+    my $GOT = '';
+    my $Z;
+    $Z = *Z;
+    my $Alen = length $Answer;
+    $status = $k->inflate($Answer, $Z) ;
+    $GOT .= $Z ;
+     
+    cmp_ok $status, '==', Z_STREAM_END, "Got Z_STREAM_END" ;
+    is $GOT, $hello, "uncompressed data matches ok" ;
+    ok ! defined $k->msg(), "No error messages" ;
+    is $k->total_in(), $Alen, "total_in ok" ;
+    is $k->total_out(), length $hello , "total_out ok";
+
+
+    ok(($k, $err) = new Compress::Raw::Zlib::Inflate);
+    ok $k, "Compress::Raw::Zlib::Inflate ok" ;
+    cmp_ok $err, '==', Z_OK, "status is Z_OK" ;
+
+    $Z = *Z;
+    $status = $k->inflate($hello, $Z);
+    is $Z, "", 'inflating *hello does not crash';
+
+    $hello = *hello;
+    $status = $k->inflateSync($hello);
+    cmp_ok $status, "!=", Z_OK,
+       "inflateSync on *hello returns error (and does not crash)";
+}
+