[Reproducible-commits] [strip-nondeterminism] 02/02: zip: catch errors when reading archive, ignore zip64 files
Andrew Ayer
agwa at andrewayer.name
Fri Jul 17 16:40:58 UTC 2015
This is an automated email from the git hooks/post-receive script.
agwa-guest pushed a commit to branch master
in repository strip-nondeterminism.
commit 1ed5c36e32fb502f2c71061bf5663284abff5421
Author: Andrew Ayer <agwa at andrewayer.name>
Date: Thu Jul 16 21:33:34 2015 -0700
zip: catch errors when reading archive, ignore zip64 files
Archive::Zip doesn't support zip64 files. Fortunately, zip64 files are
very rare, but the golang source includes zip64 files as a test case.
Fortunately these test cases don't contain any nondeterminism, so ignoring
them won't affect reproducibility.
Closes: #791574
---
lib/File/StripNondeterminism/handlers/zip.pm | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
diff --git a/lib/File/StripNondeterminism/handlers/zip.pm b/lib/File/StripNondeterminism/handlers/zip.pm
index b1be666..e2fe92f 100644
--- a/lib/File/StripNondeterminism/handlers/zip.pm
+++ b/lib/File/StripNondeterminism/handlers/zip.pm
@@ -116,10 +116,34 @@ sub normalize_extra_fields {
return $result;
}
+sub try {
+ my ($sub, $errors) = @_;
+ @$errors = ();
+ my $old_error_handler = Archive::Zip::setErrorHandler(sub { push @$errors, @_ });
+ my $res = $sub->();
+ Archive::Zip::setErrorHandler($old_error_handler);
+ return $res;
+}
+
sub normalize {
my ($zip_filename, %options) = @_;
my $filename_cmp = $options{filename_cmp} || sub { $a cmp $b };
- my $zip = Archive::Zip->new($zip_filename);
+ my $zip = Archive::Zip->new();
+ my @errors;
+ if (try(sub { $zip->read($zip_filename) }, \@errors) != AZ_OK) {
+ if (grep /zip64 not supported/, @errors) {
+ # Ignore zip64 files, which aren't supported by Archive::Zip.
+ # Ignoring unsupported files, instead of erroring out, is
+ # consistent with the rest of strip-nondeterminism's behavior,
+ # but warn about it in case someone is confused why a .zip
+ # file is left with nondeterminism in it. (Hopefully this won't
+ # happen much since zip64 files are very rare.)
+ warn "strip-nondeterminism: $zip_filename: ignoring zip64 file\n";
+ return 0;
+ } else {
+ die "Reading ZIP archive failed: " . join("\n", @errors);
+ }
+ }
my @filenames = sort $filename_cmp $zip->memberNames();
for my $filename (@filenames) {
my $member = $zip->removeMember($filename);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/strip-nondeterminism.git
More information about the Reproducible-commits
mailing list