[strip-nondeterminism] 01/01: zip: normalize NTFS FIleTimes

Reiner Herrmann reiner at reiner-h.de
Mon Nov 21 15:28:09 UTC 2016


This is an automated email from the git hooks/post-receive script.

deki-guest pushed a commit to branch master
in repository strip-nondeterminism.

commit 7124c6bf4559a2e61060a16dbd471e04b42f0239
Author: Reiner Herrmann <reiner at reiner-h.de>
Date:   Mon Nov 21 16:14:48 2016 +0100

    zip: normalize NTFS FIleTimes
    
    Closes: #845203
---
 lib/File/StripNondeterminism/handlers/zip.pm |  30 +++++++++++++++++++++++++++
 t/fixtures/zip/test.zip.in                   | Bin 0 -> 163 bytes
 t/fixtures/zip/test.zip.out                  | Bin 0 -> 163 bytes
 3 files changed, 30 insertions(+)

diff --git a/lib/File/StripNondeterminism/handlers/zip.pm b/lib/File/StripNondeterminism/handlers/zip.pm
index 56e92e2..6bbce66 100644
--- a/lib/File/StripNondeterminism/handlers/zip.pm
+++ b/lib/File/StripNondeterminism/handlers/zip.pm
@@ -79,6 +79,16 @@ use constant {
 	LOCAL_HEADER => 1
 };
 
+sub unixtime_to_winnt {
+	my $unixtime = shift || 0;
+
+	# WinNT epoch is 01-Jan-1601 00:00:00 UTC
+	# diff to unix time: `date -u -d "01-Jan-1601 00:00:00 UTC" +%s`
+	my $secondsdiff = 11644473600;
+
+	return $unixtime + $secondsdiff;
+}
+
 sub normalize_extra_fields {
 	# See http://sources.debian.net/src/zip/3.0-6/proginfo/extrafld.txt for extra field documentation
 	# $header_type is CENTRAL_HEADER or LOCAL_HEADER.
@@ -101,6 +111,26 @@ sub normalize_extra_fields {
 				$result .= pack("V",
 					$File::StripNondeterminism::canonical_time // SAFE_EPOCH);
 			}
+		} elsif ($id == 0x000a) {
+			# first 4 bytes are reserved
+			$result .= substr($field, $pos, 2+2+4);
+			my ($tag, $tagsize) = (0, 0);
+			for (my $i = 2+2+4; $i < $len; $i += $tagsize) {
+				($tag, $tagsize) = unpack("vv", substr($field, $pos + $i));
+				$result .= substr($field, $pos + $i, 2+2);
+				if ($tag == 0x0001 && $tagsize == 24) {
+					# timestamp in 1/10th microseconds
+					my $timestamp = unixtime_to_winnt($File::StripNondeterminism::canonical_time) * 10**7;
+					# mtime
+					$result .= pack("VV", $timestamp % (2**32), $timestamp / (2**32));
+					# atime
+					$result .= pack("VV", $timestamp % (2**32), $timestamp / (2**32));
+					# ctime
+					$result .= pack("VV", $timestamp % (2**32), $timestamp / (2**32));
+				} else {
+					$result .= substr($field, $pos + $i, $tagsize)
+				}
+			}
 		} elsif ($id == 0x7875) { # Info-ZIP New Unix Extra Field
 			$result .= substr($field, $pos, 4);
 		  #  Version       1 byte      version of this extra field, currently 1
diff --git a/t/fixtures/zip/test.zip.in b/t/fixtures/zip/test.zip.in
new file mode 100644
index 0000000..0b895e7
Binary files /dev/null and b/t/fixtures/zip/test.zip.in differ
diff --git a/t/fixtures/zip/test.zip.out b/t/fixtures/zip/test.zip.out
new file mode 100644
index 0000000..cf6cd07
Binary files /dev/null and b/t/fixtures/zip/test.zip.out differ

-- 
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