Subject: | Corrupt archive generated when changing compression methods (inc possible patch) |
Date: | Mon, 23 Jan 2012 19:49:23 -0000 |
To: | <bug-Archive-Zip [...] rt.cpan.org> |
From: | "Steven Hartland" <killing [...] multiplay.co.uk> |
If you create an archive using addMember from an existing
archive then change the desired compression method then
the resulting archive is corrupt.
Here's a quick example:-
#!/usr/bin/perl -w
use strict;
use Archive::Zip qw( :CONSTANTS :ERROR_CODES );
my $csv_zip = Archive::Zip->new();
my $src_zip = Archive::Zip->new('source.zip');
map {
my $member = $csv_zip->addMember( $_ );
# NOTE: changing the method here causes the issue
$member->desiredCompressionMethod( COMPRESSION_STORED );
} $src_zip->members();
my $csv_filename = 'output.zip';
my $status = $csv_zip->writeToFileNamed( $csv_filename );
if ( AZ_OK != $status )
{
print STDERR "Failed to create '$csv_filename' ($status)" );
exit 1;
}
exit 0;
The cause for this seems to be that the calculation of
headerFieldsUnknown in Zip::Member->_writeToFileHandle
doesn't take into account a change of existing compression
method and hence fails to rewrite the local file headers.
Assuming this is the case, the attached patch fixes this.
Regards
Steve
================================================
This e.mail is private and confidential between Multiplay (UK) Ltd. and the person or entity to whom it is addressed. In the event of misdirection, the recipient is prohibited from using, copying, printing or otherwise disseminating it or any information contained in it.
In the event of misdirection, illegible or incomplete transmission please telephone +44 845 868 1337
or return the E.mail to postmaster@multiplay.co.uk.
Message body is not shown because sender requested not to inline it.