(original) (raw)
changeset: 72992:12f3e86e9041 branch: 3.2 parent: 72989:f5bd78b11275 user: Senthil Kumaran senthil@uthcode.com date: Thu Oct 20 01:46:00 2011 +0800 files: Doc/library/zipfile.rst Lib/test/test_zipfile.py Lib/zipfile.py Misc/NEWS description: 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. diff -r f5bd78b11275 -r 12f3e86e9041 Doc/library/zipfile.rst --- a/Doc/library/zipfile.rst Thu Oct 20 01:05:44 2011 +0800 +++ b/Doc/library/zipfile.rst Thu Oct 20 01:46:00 2011 +0800 @@ -398,7 +398,7 @@ +-------+--------------------------+ | Index | Value | +=======+==========================+ - | ``0`` | Year | + | ``0`` | Year (>= 1980) | +-------+--------------------------+ | ``1`` | Month (one-based) | +-------+--------------------------+ @@ -411,6 +411,10 @@ | ``5`` | Seconds (zero-based) | +-------+--------------------------+ + .. note:: + + The ZIP file format does not support timestamps before 1980. + .. attribute:: ZipInfo.compress_type diff -r f5bd78b11275 -r 12f3e86e9041 Lib/test/test_zipfile.py --- a/Lib/test/test_zipfile.py Thu Oct 20 01:05:44 2011 +0800 +++ b/Lib/test/test_zipfile.py Thu Oct 20 01:46:00 2011 +0800 @@ -507,6 +507,13 @@ 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 @@ 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 -r f5bd78b11275 -r 12f3e86e9041 Lib/zipfile.py --- a/Lib/zipfile.py Thu Oct 20 01:05:44 2011 +0800 +++ b/Lib/zipfile.py Thu Oct 20 01:46:00 2011 +0800 @@ -300,6 +300,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 = b"" # Comment for each file diff -r f5bd78b11275 -r 12f3e86e9041 Misc/NEWS --- a/Misc/NEWS Thu Oct 20 01:05:44 2011 +0800 +++ b/Misc/NEWS Thu Oct 20 01:46:00 2011 +0800 @@ -54,6 +54,9 @@ - Issue #12448: smtplib now flushes stdout while running ``python -m smtplib`` in order to display the prompt correctly. +- Issue #6090: zipfile raises a ValueError when a document with a timestamp + earlier than 1980 is provided. Patch contributed by Petri Lehtinen. + - Issue #13194: zlib.compressobj().copy() and zlib.decompressobj().copy() are now available on Windows. /senthil@uthcode.com