Ovid has asked for the wisdom of the Perl Monks concerning the following question:

I'm using Archive::Zip to extract files from a zip file (duh). It works fine on my test box. In production, it it partially extracts the file and truncates the data. The index file is 21K but is getting truncated to 4K. A 135K pdf is getting truncated to 108K. All files getting extracted are getting truncated.

All files are getting truncated to a file size that is a multiple of 4K. Not *approximately* 4K, I mean exact multiples of 4K! 4,096 bytes, 20,480 bytes, 110,592 bytes, etc. This is the $Archive::Zip::ChunkSize, but I have no idea why this would be causing an issue (if that is the problem).

Production: Perl 5.00503, NT4, IIS4.
Development: Perl 5.6, Win2K, IIS5.
Both: Same versions of CGI and Archive::Zip.

I have verified that I can open the uploaded zip file on the production server and extract the files manually. Code in question is below:

Note: I did not set up the development environment!

sub unzip_and_save { # return a reference to scalar containing index.html # and a reference to array containing .pdf names my ( $zipFileName ) = @_; use Archive::Zip; my $zip = Archive::Zip->new; my $status = $zip->read( $zipFileName ); if ($status) { error( $cgi, $cgi->p("There is an error in your zip file. Ple +ase ensure that the file you are uploading is a valid archive and try + again.") ); } my ($member,$extractedFile, @pdfs, $index); foreach $member ($zip->memberNames()) { push @pdfs, $member if $member =~ /\.pdf$/i; # Add error checking to check for more than one index $index = $member if $member =~ /index\.html?$/; $extractedFile = UPLDTMPDIR . '\\' . $member; # only allow them to extract files with pdf or html extensions if ( $member =~ /\.(pdf|html?)$/i ) { my $status = $zip->extractMember($member,$extractedFile); if ( $status ) { error( $cgi, $cgi->p( "Error code: $status" ) ) if $st +atus; } } } if ( ! defined $index ) { error( $cgi, $cgi->p("No index.html file found in zip archive. +")); } elsif ( ! @pdfs ) { error( $cgi, $cgi->p("No pdfs found in zip archive")); } return ( $index, \@pdfs ); }
Anyone experienced a similar problem? I'm reading through Archive::Zip right now trying to determine what causes Archive::Zip::extractMember to stop extracting, but our clients were supposed to be using this program a couple of hours ago!

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Replies are listed 'Best First'.
Re: Archive::Zip truncating data
by Dr. Mu (Hermit) on Apr 26, 2001 at 11:28 UTC
    Are you sure your cgi script on the production machine is terminating normally? The first thing that I think of when I see files truncated to chunk multiples is that the files were never closed properly and the buffers weren't written out. (I have a little experience with Archive::Zip on a Linux machine, but have never come across this problem.)
Re: Archive::Zip truncating data
by Albannach (Monsignor) on Apr 26, 2001 at 18:36 UTC
    You've probably checked this, but just in case: you mention that they have the same versions of Archive::ZIP, but what about Compress::Zlib upon which the former relies? Revision notes I've found mention a nasty output truncation problem in versions prior to 1.06 of Compress::Zlib.

    --
    I'd like to be able to assign to an luser

      Albannach wrote:
      You've probably checked this, but just in case...
      Please, don't give me too much credit :) As it turns out, I had Version 1.03 of Compress::Zlib and that was probably the problem. I tried to upgrade it, but when I ran make, it turns out that I didn't have cl.exe. Rather than installing Visual C++ on the box (which I understand cl.exe comes from), I went out and tried to find a stand-alone version. Couldn't find it, but the boss said to go ahead and upgrade Perl to 5.6.1, which has the newer version of Compress::Zlib.

      Unfortunately, ActiveState's 5.6.1 is listed as beta, so we opted for 5.6, which I understand has some issues with memory leaks. And this is being run on an NT server! It fixed the problem, but I can't help but wonder if I stomped on a big, fat cockroach only to discover that I let in a bunch of little, invisible fleas in. Personally, I would much rather have upgraded the one module rather than the entire Perl installation, but it wasn't my call (and we were over-deadline, so I can understand the decision that was taken).

      In any event, thank you very much, Albannach. Your idea put us on the right path. If you're ever in Portland, OR, let me know and I'll buy you a beer or seven -- or whatever it is that you're inclined to drink :)

      Cheers,
      Ovid

      Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.