Fix closes Issue6090 - Raise a ValueError, instead of failing with unrelated
exceptions, when a document with timestamp earlier than 1980 is provided to
zipfile. Patch contributed by Petri Lehtinen.
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
index 6cba26c..7ebb663 100644
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -477,6 +477,12 @@
except zipfile.BadZipfile:
self.assertTrue(zipfp2.fp is None, 'zipfp is not closed')
+ def test_add_file_before_1980(self):
+ # Set atime and mtime to 1970-01-01
+ os.utime(TESTFN, (0, 0))
+ with zipfile.ZipFile(TESTFN2, "w") as zipfp:
+ self.assertRaises(ValueError, zipfp.write, TESTFN)
+
def tearDown(self):
unlink(TESTFN)
unlink(TESTFN2)
@@ -990,6 +996,10 @@
pass
self.assertRaises(zipfile.BadZipfile, zipfile.ZipFile, TESTFN, 'r')
+ def test_create_zipinfo_before_1980(self):
+ self.assertRaises(ValueError,
+ zipfile.ZipInfo, 'seventies', (1979, 1, 1, 0, 0, 0))
+
def tearDown(self):
unlink(TESTFN)
unlink(TESTFN2)
diff --git a/Lib/zipfile.py b/Lib/zipfile.py
index f876f42..d9181f2 100644
--- a/Lib/zipfile.py
+++ b/Lib/zipfile.py
@@ -290,6 +290,10 @@
self.filename = filename # Normalized file name
self.date_time = date_time # year, month, day, hour, min, sec
+
+ if date_time[0] < 1980:
+ raise ValueError('ZIP does not support timestamps before 1980')
+
# Standard values:
self.compress_type = ZIP_STORED # Type of compression for the file
self.comment = "" # Comment for each file