diff options
author | Senthil Kumaran <senthil@uthcode.com> | 2011-10-19 17:46:00 (GMT) |
---|---|---|
committer | Senthil Kumaran <senthil@uthcode.com> | 2011-10-19 17:46:00 (GMT) |
commit | 29fa9d4d68af7d22b88545fa8bc4ae186d256fd3 (patch) | |
tree | 1f884092ef016b20bffeec3566e0323d82ddf221 /Lib | |
parent | 1ef0c0349e8fdb5415e21231cb42edbf232b742a (diff) | |
download | cpython-29fa9d4d68af7d22b88545fa8bc4ae186d256fd3.zip cpython-29fa9d4d68af7d22b88545fa8bc4ae186d256fd3.tar.gz cpython-29fa9d4d68af7d22b88545fa8bc4ae186d256fd3.tar.bz2 |
3.2 - 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.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_zipfile.py | 11 | ||||
-rw-r--r-- | Lib/zipfile.py | 4 |
2 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py index 782020c..bb0d79a 100644 --- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -507,6 +507,13 @@ class TestsWithSourceFile(unittest.TestCase): 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) + + @skipUnless(zlib, "requires zlib") def test_unicode_filenames(self): # bug #10801 @@ -1053,6 +1060,10 @@ class OtherTests(unittest.TestCase): f.close() 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 5cc7816..6ca269f 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -300,6 +300,10 @@ class ZipInfo (object): 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 = b"" # Comment for each file |