[Python-checkins] cpython (2.7): Fix closes Issue6090 - Raise a ValueError, instead of failing with unrelated
senthil.kumaran
python-checkins at python.org
Wed Oct 19 19:52:58 CEST 2011
http://hg.python.org/cpython/rev/649ac338203f
changeset: 72991:649ac338203f
branch: 2.7
parent: 72988:489237756488
user: Senthil Kumaran <senthil at uthcode.com>
date: Thu Oct 20 01:38:35 2011 +0800
summary:
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.
files:
Doc/library/zipfile.rst | 6 +++++-
Lib/test/test_zipfile.py | 10 ++++++++++
Lib/zipfile.py | 4 ++++
Misc/NEWS | 3 +++
4 files changed, 22 insertions(+), 1 deletions(-)
diff --git a/Doc/library/zipfile.rst b/Doc/library/zipfile.rst
--- a/Doc/library/zipfile.rst
+++ b/Doc/library/zipfile.rst
@@ -388,7 +388,7 @@
+-------+--------------------------+
| Index | Value |
+=======+==========================+
- | ``0`` | Year |
+ | ``0`` | Year (>= 1980) |
+-------+--------------------------+
| ``1`` | Month (one-based) |
+-------+--------------------------+
@@ -401,6 +401,10 @@
| ``5`` | Seconds (zero-based) |
+-------+--------------------------+
+ .. note::
+
+ The ZIP file format does not support timestamps before 1980.
+
.. attribute:: ZipInfo.compress_type
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
--- 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
--- 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
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -63,6 +63,9 @@
Library
-------
+- 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.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list