Skip Menu |

This queue is for tickets about the Compress-Bzip2 CPAN distribution.

Report information
The Basics
Id: 48128
Status: resolved
Priority: 0/
Queue: Compress-Bzip2

People
Owner: Nobody in particular
Requestors: scop [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 2.09
Fixed in: (no value)



Subject: memBzip and memBunzip do not generate/read valid bzip2 files
memBzip adds and memBunzip expects to find 5 bytes of some data at the beginning of their buffers which is not valid bzip as far as I can tell. Bzip2 files/streams should start with BZh; I don't know what the 5 bytes added/expexcted by memBzip/memBunzip before that are there for, but they seem to make them incompatible with standard formatted bzip2 streams/files and other bzip2 tools. Patch to test suite attached that starts adding a bit of these tests, and causes it to currently fail. This is on Fedora 10 x86_64, perl v5.10.0, system bzip2 1.0.5
Subject: Compress-Bzip2-mem.patch
diff -up Compress-Bzip2-2.09/t/040-memory.t~ Compress-Bzip2-2.09/t/040-memory.t --- Compress-Bzip2-2.09/t/040-memory.t~ 2005-04-21 19:57:48.000000000 +0300 +++ Compress-Bzip2-2.09/t/040-memory.t 2009-07-23 23:35:29.000000000 +0300 @@ -1,6 +1,6 @@ # -*- mode: perl -*- -use Test::More tests => 10; +use Test::More tests => 12; #use Test::More qw(no_plan); BEGIN { @@ -18,6 +18,8 @@ and the Momewrathes outgrabe my $compress = memBzip( $string ); my $uncompress = memBunzip( $compress ); +ok( $compress =~ /^BZh/, "compressed starts with bzip magic header" ); + ok( $compress ne $string, "string was not inouted" ); ok( length($compress)-10 < length($string), "string compression - ".length($compress).' vs '.length($string) ); ok( $uncompress eq $string, "uncompressed is same as the original" ); @@ -36,3 +38,16 @@ $uncompress = decompress( $compress ); ok( $compress ne $string, "bzip1 string was not inouted" ); ok( length($compress)-10 < length($string), "bzip1 string compression - ".length($compress).' vs '.length($string) ); ok( $uncompress eq $string, "bzip1 decompress is same as the original" ); + +do 't/lib.pl'; + +my $sample0; +my $INFILE = catfile( qw(bzlib-src sample0.bz2) ); +local $/ = undef; +open( IN, "< $INFILE" ) or die "$INFILE: $!"; +binmode IN; +$sample0 = <IN>; +close( IN ); + +$uncompress = memBunzip( "$sample0" ); # copy +ok( $uncompress, "sample0 uncompressed" );
On Thu Jul 23 16:41:09 2009, SCOP wrote: Show quoted text
> memBzip adds and memBunzip expects to find 5 bytes of some data at the > beginning of their buffers which is not valid bzip as far as I can tell. > > Bzip2 files/streams should start with BZh; I don't know what the 5 bytes > added/expexcted by memBzip/memBunzip before that are there for, but they > seem to make them incompatible with standard formatted bzip2 > streams/files and other bzip2 tools.
This is invalid. The memory/stream API adds a $stream->prefix header to be able to allocate the result buffer before. See t/082-stream.t Yes, this is a bit unfortunate. memBunzip should also accept plain BZh headers and realloc the result buffer after decompression. I'll add this feature in my version at https://github.com/rurban/Compress-Bzip2 -- Reini Urban
Show quoted text
> memBunzip should also accept plain BZh headers and realloc the result > buffer after decompression. > I'll add this feature in my version at > https://github.com/rurban/Compress-Bzip2
Fixed with * 94e6ded : [cpan #48128] support memBunzip BZh header w/o extra size prefix -- Reini Urban
Show quoted text
> memBunzip should also accept plain BZh headers and realloc the result > buffer after decompression. > I'll add this feature in my version at > https://github.com/rurban/Compress-Bzip2
Fixed with * 94e6ded : [cpan #48128] support memBunzip BZh header w/o extra size prefix -- Reini Urban