Commit 7e3062b3 authored by Senthil Kumaran's avatar Senthil Kumaran

default - 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.
parents 294c231a 29fa9d4d
...@@ -398,7 +398,7 @@ Instances have the following attributes: ...@@ -398,7 +398,7 @@ Instances have the following attributes:
+-------+--------------------------+ +-------+--------------------------+
| Index | Value | | Index | Value |
+=======+==========================+ +=======+==========================+
| ``0`` | Year | | ``0`` | Year (>= 1980) |
+-------+--------------------------+ +-------+--------------------------+
| ``1`` | Month (one-based) | | ``1`` | Month (one-based) |
+-------+--------------------------+ +-------+--------------------------+
...@@ -411,6 +411,10 @@ Instances have the following attributes: ...@@ -411,6 +411,10 @@ Instances have the following attributes:
| ``5`` | Seconds (zero-based) | | ``5`` | Seconds (zero-based) |
+-------+--------------------------+ +-------+--------------------------+
.. note::
The ZIP file format does not support timestamps before 1980.
.. attribute:: ZipInfo.compress_type .. attribute:: ZipInfo.compress_type
......
...@@ -500,6 +500,18 @@ class TestsWithSourceFile(unittest.TestCase): ...@@ -500,6 +500,18 @@ class TestsWithSourceFile(unittest.TestCase):
except zipfile.BadZipFile: except zipfile.BadZipFile:
self.assertTrue(zipfp2.fp is None, 'zipfp is not closed') 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)
@requires_zlib @requires_zlib
def test_unicode_filenames(self): def test_unicode_filenames(self):
# bug #10801 # bug #10801
...@@ -1046,6 +1058,10 @@ class OtherTests(unittest.TestCase): ...@@ -1046,6 +1058,10 @@ class OtherTests(unittest.TestCase):
f.close() f.close()
self.assertRaises(zipfile.BadZipFile, zipfile.ZipFile, TESTFN, 'r') 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): def tearDown(self):
unlink(TESTFN) unlink(TESTFN)
unlink(TESTFN2) unlink(TESTFN2)
......
...@@ -300,6 +300,10 @@ class ZipInfo (object): ...@@ -300,6 +300,10 @@ class ZipInfo (object):
self.filename = filename # Normalized file name self.filename = filename # Normalized file name
self.date_time = date_time # year, month, day, hour, min, sec 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: # Standard values:
self.compress_type = ZIP_STORED # Type of compression for the file self.compress_type = ZIP_STORED # Type of compression for the file
self.comment = b"" # Comment for each file self.comment = b"" # Comment for each file
......
...@@ -319,6 +319,9 @@ Core and Builtins ...@@ -319,6 +319,9 @@ Core and Builtins
Library Library
------- -------
- Issue #6090: zipfile raises a ValueError when a document with a timestamp
earlier than 1980 is provided. Patch contributed by Petri Lehtinen.
- Issue #13150: sysconfig no longer parses the Makefile and config.h files - Issue #13150: sysconfig no longer parses the Makefile and config.h files
when imported, instead doing it at build time. This makes importing when imported, instead doing it at build time. This makes importing
sysconfig faster and reduces Python startup time by 20%. sysconfig faster and reduces Python startup time by 20%.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment