[Git][reproducible-builds/strip-nondeterminism][master] 2 commits: Do not fail on JAR archives containing invalid members with a .jar extension

Chris Lamb (@lamby) gitlab at salsa.debian.org
Mon Nov 22 18:55:48 UTC 2021



Chris Lamb pushed to branch master at Reproducible Builds / strip-nondeterminism


Commits:
763f4f83 by Jonas Witschel at 2021-11-22T17:40:56+01:00
Do not fail on JAR archives containing invalid members with a .jar extension

_jar_normalize_member() in the JAR handler calls
File::StripNondeterminism::handlers::zip::normalize_member for every archive
member with a .jar extension. If the member is not a valid archive (e.g.
because it is just an empty file), this leads to a hard failure "Reading ZIP
archive failed" in the ZIP handler.

To solve this, extend normalize_member() in the ZIP file to detect the file
type if no $normalizer is explicitly specified. This uses
get_normalizer_for_file(), which looks at both the file extension and the
"file" command to detect the type more accurately. Therefore we need to
preserve the name of the extracted temporary file instead of just calling it
"member".

With this change in place, we can leave the normalizer for files with a .jar
extension unspecified in _jar_normalize_member(). This way if the file is not
an archive, it will get skipped by get_normalizer_for_file() and a warning will
be printed instead of a fatal error.

- - - - -
d1c896fd by Chris Lamb at 2021-11-22T18:55:44+00:00
Merge branch 'dont-fail-on-wrong-jar-extension' into 'master'

Do not fail on JAR archives containing invalid members with a .jar extension

See merge request reproducible-builds/strip-nondeterminism!13
- - - - -


2 changed files:

- lib/File/StripNondeterminism/handlers/jar.pm
- lib/File/StripNondeterminism/handlers/zip.pm


Changes:

=====================================
lib/File/StripNondeterminism/handlers/jar.pm
=====================================
@@ -123,7 +123,7 @@ sub _jar_normalize_member($$) {
 		$timestamp--;
 	} elsif ($member->fileName() =~ /\.jar$/) {
 		File::StripNondeterminism::handlers::zip::normalize_member($member,
-			\&normalize);
+			undef);
 	}
 
 	return $timestamp;


=====================================
lib/File/StripNondeterminism/handlers/zip.pm
=====================================
@@ -22,6 +22,7 @@ package File::StripNondeterminism::handlers::zip;
 use strict;
 use warnings;
 
+use File::Basename qw(basename);
 use File::Temp;
 use File::StripNondeterminism;
 use Archive::Zip qw/:CONSTANTS :ERROR_CODES/;
@@ -65,13 +66,19 @@ sub normalize_member($$) {
 
 	# Extract the member to a temporary file.
 	my $tempdir = File::Temp->newdir();
-	my $filename = "$tempdir/member";
+	my $filename = "$tempdir/" . basename($member->fileName());
 	my $original_size = $member->compressedSize();
 	$member->extractToFileNamed($filename);
 	chmod(0600, $filename);
 	$member->{'compressedSize'} = $original_size
 	  ; # Work around https://github.com/redhotpenguin/perl-Archive-Zip/issues/11
 
+	$normalizer = File::StripNondeterminism::get_normalizer_for_file($filename) unless defined $normalizer;
+	if (not defined $normalizer) {
+		warn "strip-nondeterminism: unknown file type of " . $member->fileName();
+		return;
+	}
+
 	# Normalize the temporary file.
 	if ($normalizer->($filename)) {
 		# Normalizer modified the temporary file.



View it on GitLab: https://salsa.debian.org/reproducible-builds/strip-nondeterminism/-/compare/ba5a0ac2297ec4bb6bd76d0d32881b1120aae62c...d1c896fdfa7fe59666d68739a03f65b211537a75

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/strip-nondeterminism/-/compare/ba5a0ac2297ec4bb6bd76d0d32881b1120aae62c...d1c896fdfa7fe59666d68739a03f65b211537a75
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20211122/0f50f9f9/attachment.htm>


More information about the rb-commits mailing list