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.


In reply to Archive::Zip truncating data by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.