[Reproducible-builds] [PATCH] remove non-determinism from timestamps in extra fields of zip files
Reiner Herrmann
reiner at reiner-h.de
Fri Dec 12 18:30:12 UTC 2014
Closes: #765304
---
lib/File/StripNondeterminism/handlers/zip.pm | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/lib/File/StripNondeterminism/handlers/zip.pm b/lib/File/StripNondeterminism/handlers/zip.pm
index 75e4c7b..b902a23 100644
--- a/lib/File/StripNondeterminism/handlers/zip.pm
+++ b/lib/File/StripNondeterminism/handlers/zip.pm
@@ -62,6 +62,29 @@ sub normalize_member {
unlink($filename);
}
+sub normalize_extra_fields {
+ my $field = shift;
+
+ my $result = "";
+ my $pos = 0;
+ my ($id, $len);
+
+ # field format: 2 bytes id, 2 bytes data len, n bytes data
+ while (($id, $len) = unpack("SS", substr($field, $pos))) {
+ if ($id == 0x5455) {
+ # extended timestamp found.
+ # first byte of data contains flags.
+ $result .= substr($field, $pos, 5) . pack("L", $File::StripNondeterminism::canonical_time // SAFE_EPOCH);
+ } else {
+ # use the current extra field unmodified.
+ $result .= substr($field, $pos, $len+4);
+ }
+ $pos += $len + 4;
+ }
+
+ return $result;
+}
+
sub normalize {
my ($zip_filename, %options) = @_;
my $filename_cmp = $options{filename_cmp} || sub { $a cmp $b };
@@ -72,6 +95,7 @@ sub normalize {
$zip->addMember($member);
$options{member_normalizer}->($member) if exists $options{member_normalizer};
$member->setLastModFileDateTimeFromUnix($File::StripNondeterminism::canonical_time // SAFE_EPOCH);
+ $member->cdExtraField(normalize_extra_fields($member->cdExtraField()));
}
$zip->overwrite();
return 1;
--
2.1.3
More information about the Reproducible-builds
mailing list