Fix ijar's timestamp normalization
0 is not a valid DOS timestamp, days and months start at 1.
--
PiperOrigin-RevId: 141818782
MOS_MIGRATED_REVID=141818782
diff --git a/third_party/ijar/test/ijar_test.sh b/third_party/ijar/test/ijar_test.sh
index 92b5229..0b9a92f 100755
--- a/third_party/ijar/test/ijar_test.sh
+++ b/third_party/ijar/test/ijar_test.sh
@@ -228,9 +228,9 @@
"Interface jar should contain only .class files!"
- # Check that -interface.jar timestamps are all zeros:
+ # Check that -interface.jar timestamps are normalized:
check_eq 0 $(TZ=UTC $JAR tvf $A_INTERFACE_JAR |
- grep -v 'Fri Nov 30 00:00:00 UTC 1979' | wc -l) \
+ grep -v 'Tue Jan 01 00:00:00 UTC 1980' | wc -l) \
"Interface jar contained non-zero timestamps!"
diff --git a/third_party/ijar/zip.cc b/third_party/ijar/zip.cc
index 6fd9590..957407b 100644
--- a/third_party/ijar/zip.cc
+++ b/third_party/ijar/zip.cc
@@ -73,6 +73,8 @@
// http://www.info-zip.org/FAQ.html#limits
static const u8 kMaximumOutputSize = std::numeric_limits<uint32_t>::max();
+static const u4 kDosEpoch = 1 << 21 | 1 << 16; // January 1, 1980 in DOS time
+
//
// A class representing a ZipFile for reading. Its public API is exposed
// using the ZipExtractor abstract class.
@@ -871,8 +873,7 @@
put_u2le(q, 10); // extract_version
put_u2le(q, 0); // general_purpose_bit_flag
put_u2le(q, 0); // compression_method
- put_u2le(q, 0); // last_mod_file_time
- put_u2le(q, 0); // last_mod_file_date
+ put_u4le(q, kDosEpoch); // last_mod_file date and time
put_u4le(q, entry->crc32); // crc32
put_u4le(q, 0); // compressed_size
put_u4le(q, 0); // uncompressed_size
@@ -903,8 +904,7 @@
put_u2le(q, ZIP_VERSION_TO_EXTRACT); // version to extract
put_u2le(q, 0); // general purpose bit flag
put_u2le(q, entry->compression_method); // compression method:
- put_u2le(q, 0); // last_mod_file_time
- put_u2le(q, 0); // last_mod_file_date
+ put_u4le(q, kDosEpoch); // last_mod_file date and time
put_u4le(q, entry->crc32); // crc32
put_u4le(q, entry->compressed_length); // compressed_size
put_u4le(q, entry->uncompressed_length); // uncompressed_size
@@ -995,8 +995,7 @@
put_u2le(q, 0); // general purpose bit flag
u1 *header_ptr = q;
put_u2le(q, COMPRESSION_METHOD_STORED); // compression method = placeholder
- put_u2le(q, 0); // last_mod_file_time
- put_u2le(q, 0); // last_mod_file_date
+ put_u4le(q, kDosEpoch); // last_mod_file date and time
put_u4le(q, entry->crc32); // crc32
put_u4le(q, 0); // compressed_size = placeholder
put_u4le(q, 0); // uncompressed_size = placeholder