Hi,
as reported by Vincent Lefevre in <http://bugs.debian.org/521613>,
Archive::Tar->read() could check a bit better for errors. Corrupted
archives shorter than 512 bytes will not currently set the error string.
I'm attaching a test case and a proposed patch for this.
Thanks for your work,
--
Niko Tyni
ntyni@debian.org
Subject: | 521613.patch |
diff --git a/lib/Archive/Tar.pm b/lib/Archive/Tar.pm
index 09dab10..117ca35 100644
--- a/lib/Archive/Tar.pm
+++ b/lib/Archive/Tar.pm
@@ -323,6 +323,10 @@ sub _read_tar {
$self->_error( qq[Cannot read compressed format in tar-mode] );
return;
}
+ if (length $chunk != HEAD) {
+ $self->_error( qq[Cannot read enough bytes from the tarfile] );
+ return;
+ }
}
### if we can't read in all bytes... ###
diff --git a/t/04_resolved_issues.t b/t/04_resolved_issues.t
index 89756cd..e4e82a1 100644
--- a/t/04_resolved_issues.t
+++ b/t/04_resolved_issues.t
@@ -167,3 +167,15 @@ use_ok( $FileClass );
ok( $file->validate, " File validates" );
}
}
+
+### return error properly on corrupted archives
+{ ok( 1, "Testing error reporting with a short corrupted archive" );
+ no warnings 'once'; $Archive::Tar::error = "";
+ my $src = File::Spec->catfile( qw[src short b] );
+ my $tar = $Class->new;
+
+ isa_ok( $tar, $Class, " Object" );
+ ok( !$tar->read( $src ), " No files in the corrupted archive" );
+ ok( $tar->error ne "", " Nonempty error when reading the corrupted archive" );
+}
+