Skip Menu |

This queue is for tickets about the Archive-Zip CPAN distribution.

Report information
The Basics
Id: 27463
Status: resolved
Worked: 2 hours (120 min)
Priority: 0/
Queue: Archive-Zip

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

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



Subject: Archive::Zip does not correctly add files named "0" (zero)
Hello, We've just discovered that Archive::Zip can't handle files names "0" (zero). Yes I know what you think right now but don't ask why or how, I'm not the one who chose to use such a name :-/ Here is a small script to demonstrate the problem: use strict; use Archive::Zip; my $path = shift || die "need a file or directory name\n"; my $archive = Archive::Zip->new; $archive->addTree($path, $path); $archive->writeToFileNamed("$path.zip"); and a directory with two files (named "0" and "1"): $ ls -lF folder/ -rw-r--r-- 1 saper saper 35587 jun 6 11:45 0 -rwxr-xr-x 1 saper saper 2530 jun 6 11:46 1* Now if I execute the script $ perl archive-zip.pl folder the created archive looks like this: $ unzip -l folder.zip Archive: folder.zip Length Date Time Name -------- ---- ---- ---- 0 06-06-07 15:02 folder/ 35587 06-06-07 11:45 folder/ 2530 06-06-07 11:46 folder/1 -------- ------- 38117 3 files The entry for "0" is here, except for its name. After digging through Archive::Zip code, I isolated the bug in the function _asZipDirName(). Attached is the patch to fix it. Thanks in advance -- Close the world, txEn eht nepO.
Subject: Archive-Zip-1.20-handle-zero.diff
diff -ru Archive-Zip-1.20-orig/lib/Archive/Zip.pm Archive-Zip-1.20/lib/Archive/Zip.pm --- Archive-Zip-1.20-orig/lib/Archive/Zip.pm 2007-06-05 03:48:29.000000000 +0200 +++ Archive-Zip-1.20/lib/Archive/Zip.pm 2007-06-06 15:40:59.842075006 +0200 @@ -514,7 +514,7 @@ $$volReturn = $volume if ( ref($volReturn) ); my @dirs = map { $_ =~ s{/}{_}g; $_ } File::Spec->splitdir($directories); if ( @dirs > 0 ) { pop (@dirs) unless $dirs[-1] } # remove empty component - push ( @dirs, $file || '' ); + push ( @dirs, defined($file) ? $file : '' ); #return wantarray ? @dirs : join ( '/', @dirs ); return join ( '/', @dirs ); }
Hi! Attached is an improved patch that also adds a regression test against this bug. I could not commit it to ADAMK's "Open Repository" so I'm posting it here. Regards, Shlomi Fish On Wed Jun 06 09:58:41 2007, SAPER wrote: Show quoted text
> Hello, > > We've just discovered that Archive::Zip can't handle files names "0" > (zero). Yes I know what you think right now but don't ask why or how, > I'm not the one who chose to use such a name :-/ > > Here is a small script to demonstrate the problem: > > use strict; > use Archive::Zip; > my $path = shift || die "need a file or directory name\n"; > my $archive = Archive::Zip->new; > $archive->addTree($path, $path); > $archive->writeToFileNamed("$path.zip"); > > and a directory with two files (named "0" and "1"): > > $ ls -lF folder/ > -rw-r--r-- 1 saper saper 35587 jun 6 11:45 0 > -rwxr-xr-x 1 saper saper 2530 jun 6 11:46 1* > > Now if I execute the script > > $ perl archive-zip.pl folder > > the created archive looks like this: > > $ unzip -l folder.zip > Archive: folder.zip > Length Date Time Name > -------- ---- ---- ---- > 0 06-06-07 15:02 folder/ > 35587 06-06-07 11:45 folder/ > 2530 06-06-07 11:46 folder/1 > -------- ------- > 38117 3 files > > The entry for "0" is here, except for its name. > > After digging through Archive::Zip code, I isolated the bug in the > function _asZipDirName(). Attached is the patch to fix it. > > > Thanks in advance
Index: t/07_filenames_of_0.t =================================================================== --- t/07_filenames_of_0.t (revision 0) +++ t/07_filenames_of_0.t (revision 0) @@ -0,0 +1,40 @@ +#!/usr/bin/perl -w + +# This is a regression test for: +# http://rt.cpan.org/Public/Bug/Display.html?id=27463 +# +# It tests that one can add files to the archive whose filenames are "0". + +use strict; +use warnings; + +use Test::More tests => 1; +use Archive::Zip; + +use File::Path; +use File::Spec; + +use constant TESTDIR => ('testdir'); +use constant TEST_FOLDER => (TESTDIR(), "folder"); + +mkpath([ File::Spec->catdir(TEST_FOLDER()) ]); + +open O, ">", File::Spec->catfile(TEST_FOLDER(), "0"); +print O "File 0\n"; +close(O); + +open O, ">", File::Spec->catfile(TEST_FOLDER(), "1"); +print O "File 1\n"; +close(O); + +my $archive = Archive::Zip->new; + +$archive->addTree(File::Spec->catfile(TEST_FOLDER()), "folder"); + +# TEST +ok(scalar(grep { $_ eq "folder/0" } $archive->memberNames()), + "Checking that a file called '0' was added properly" +); + +rmtree([ File::Spec->catdir(TEST_FOLDER()) ]); + Index: lib/Archive/Zip.pm =================================================================== --- lib/Archive/Zip.pm (revision 1983) +++ lib/Archive/Zip.pm (working copy) @@ -514,7 +514,7 @@ $$volReturn = $volume if ( ref($volReturn) ); my @dirs = map { $_ =~ s{/}{_}g; $_ } File::Spec->splitdir($directories); if ( @dirs > 0 ) { pop (@dirs) unless $dirs[-1] } # remove empty component - push ( @dirs, $file || '' ); + push ( @dirs, defined($file) ? $file : '' ); #return wantarray ? @dirs : join ( '/', @dirs ); return join ( '/', @dirs ); } Index: Changes =================================================================== --- Changes (revision 1983) +++ Changes (working copy) @@ -1,5 +1,8 @@ Revision history for Perl extension Archive::Zip + - fixed http://rt.cpan.org/Public/Bug/Display.html?id=27463 with a regression + test - cannot add files whose entire filenames are "0". (SHLOMIF). + 1.20 Tue 5 Jun 2007 - Adam Kennedy - Removing dependency on File::Which due to public outburst of flaming on cpanra(n)tings by H.Merijn Brand. Try a simple email next time. :(
From: SHLOMIF [...] cpan.org
On Mon Jul 30 15:32:49 2007, SHLOMIF wrote: Show quoted text
> Hi! > > Attached is an improved patch that also adds a regression test
against Show quoted text
> this bug. > > I could not commit it to ADAMK's "Open Repository" so I'm posting it
here. Show quoted text
>
This patch was applied to the Archive-Zip repository after I got repository access: {{{{{{{{{{{{{{{{{{{{ r2166 | shlomif@cpan.org | 2007-10-03 13:02:51 +0200 (Wed, 03 Oct 2007) | 6 lines Changed paths: M /trunk/Archive-Zip/Changes M /trunk/Archive-Zip/lib/Archive/Zip.pm A /trunk/Archive-Zip/t/07_filenames_of_0.t Added a fix for the bug http://rt.cpan.org/Public/Bug/Display.html?id=27463 : <<< Archive::Zip does not correctly add files named "0". Show quoted text
>>>
}}}}}}}}}}}}}}}}}}} Regards, Shlomi Fish Show quoted text
> Regards, > > Shlomi Fish > > > On Wed Jun 06 09:58:41 2007, SAPER wrote:
> > Hello, > > > > We've just discovered that Archive::Zip can't handle files
names "0" Show quoted text
> > (zero). Yes I know what you think right now but don't ask why or
how, Show quoted text
> > I'm not the one who chose to use such a name :-/ > > > > Here is a small script to demonstrate the problem: > > > > use strict; > > use Archive::Zip; > > my $path = shift || die "need a file or directory name\n"; > > my $archive = Archive::Zip->new; > > $archive->addTree($path, $path); > > $archive->writeToFileNamed("$path.zip"); > > > > and a directory with two files (named "0" and "1"): > > > > $ ls -lF folder/ > > -rw-r--r-- 1 saper saper 35587 jun 6 11:45 0 > > -rwxr-xr-x 1 saper saper 2530 jun 6 11:46 1* > > > > Now if I execute the script > > > > $ perl archive-zip.pl folder > > > > the created archive looks like this: > > > > $ unzip -l folder.zip > > Archive: folder.zip > > Length Date Time Name > > -------- ---- ---- ---- > > 0 06-06-07 15:02 folder/ > > 35587 06-06-07 11:45 folder/ > > 2530 06-06-07 11:46 folder/1 > > -------- ------- > > 38117 3 files > > > > The entry for "0" is here, except for its name. > > > > After digging through Archive::Zip code, I isolated the bug in the > > function _asZipDirName(). Attached is the patch to fix it. > > > > > > Thanks in advance
> >
Fixed in repository and in Archive-Zip-1.21.