Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"CRC or size mismatch" when extracting member second time #11

Closed
AGWA opened this issue Feb 5, 2015 · 5 comments
Closed

"CRC or size mismatch" when extracting member second time #11

AGWA opened this issue Feb 5, 2015 · 5 comments

Comments

@AGWA
Copy link
Contributor

AGWA commented Feb 5, 2015

If I try to extract the same member more than once, the second extraction results in:

format error: CRC or size mismatch while skipping data descriptor 
 at /tmp/perl-Archive-Zip/lib/Archive/Zip/ZipFileMember.pm line 192
        Archive::Zip::ZipFileMember::_skipLocalFileHeader('Archive::Zip::ZipFileMember=HASH(0x19e0af0)') called at /tmp/perl-Archive-Zip/lib/Archive/Zip/ZipFileMember.pm line 395
        Archive::Zip::ZipFileMember::rewindData('Archive::Zip::ZipFileMember=HASH(0x19e0af0)') called at /tmp/perl-Archive-Zip/lib/Archive/Zip/Member.pm line 1023
        Archive::Zip::Member::extractToFileHandle('Archive::Zip::ZipFileMember=HASH(0x19e0af0)', 'IO::File=GLOB(0x1ac32f8)') called at /tmp/perl-Archive-Zip/lib/Archive/Zip/Member.pm line 506
        Archive::Zip::Member::extractToFileNamed('Archive::Zip::ZipFileMember=HASH(0x19e0af0)', 'zipout2') called at ./crc_error.pl line 12

This only happens with some Zip files. It seems to happen consistently with Zip files created with the jar command.

Here is a test case:

#!/usr/bin/perl

use Archive::Zip;

my $zip = Archive::Zip->new($ARGV[0]);
my $member = $zip->memberNamed('FILE');
$member->extractToFileNamed("zipout1");
$member->extractToFileNamed("zipout2");
  • Zip file that triggers the bug (created with the jar command): bad.zip
  • Zip file that does not trigger the bug (contains the same contents as bad.zip but was created with InfoZip): good.zip

I tracked the problem down to _writeData modifying compressedSize on line 1103 of lib/Archive/Zip/Member.pm:

 $self->{'compressedSize'} = $self->_writeOffset();

Because compressedSize has been modified, the next time that the member is extracted, _skipLocalFileHeader will seek an incorrect number of bytes on line 175 of lib/Archive/Zip/ZipFileMember.pm:

 $self->fh()->seek($self->{'compressedSize'}, IO::Seekable::SEEK_CUR)

I don't understand why compressedSize is being set in _writeData to what is essentially the _un_compressed length of the member. If I remove that line, the bug is fixed and Archive::Zip's test suite still passes. Of course, there may be a good reason for that line that I'm not aware of, which is why I'm not submitting a patch. What do you think the correct fix is?

Thanks!

@redhotpenguin
Copy link
Owner

Ok would you mind putting together a pull request that implements this so I can evaluate it?

@redhotpenguin
Copy link
Owner

Thanks for the patch - I'll try to add a test and release.

@pwr22
Copy link
Contributor

pwr22 commented Mar 19, 2015

@AGWA Can you state on here that you release your test code and archives (these in particular) under the same licensing terms as Archive::Zip? This is silly to have to ask but I've seen this trip up acceptance of this sort of stuff into upstream linux distros cough Debian cough

I'm working on a test for this now

pwr22 added a commit to pwr22/perl-Archive-Zip that referenced this issue Mar 19, 2015
@AGWA
Copy link
Contributor Author

AGWA commented Mar 22, 2015

@pwr22 Thanks for working on this. Yes, I do release my test code and archives under the same licensing terms as Archive::Zip.

redhotpenguin added a commit that referenced this issue Mar 25, 2015
@redhotpenguin
Copy link
Owner

@pwr22 @AGWA thank you guys so much for providing this. 1.46 is going out tonight with these changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants