summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_zipfile.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-01-31 13:30:36 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-01-31 13:30:36 (GMT)
commitdb58e15ee55c66fd4900be2ab2e02b864ae2313e (patch)
tree73c325289c348d184ee08c072ebc211114c74157 /Lib/test/test_zipfile.py
parent04e3cca0f982326a4fed3b688bfa7bc119e2c58a (diff)
parentd72bfe9eb90da597b41b37ce32f87f995a2c22c5 (diff)
downloadcpython-db58e15ee55c66fd4900be2ab2e02b864ae2313e.zip
cpython-db58e15ee55c66fd4900be2ab2e02b864ae2313e.tar.gz
cpython-db58e15ee55c66fd4900be2ab2e02b864ae2313e.tar.bz2
Issue #4844: ZipFile now raises BadZipFile when opens a ZIP file with an
incomplete "End of Central Directory" record. Original patch by Guilherme Polo and Alan McIntyre.
Diffstat (limited to 'Lib/test/test_zipfile.py')
-rw-r--r--Lib/test/test_zipfile.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
index 88b2aa2..5d9a241 100644
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -996,6 +996,20 @@ class OtherTests(unittest.TestCase):
chk = zipfile.is_zipfile(fp)
self.assertTrue(not chk)
+ def test_damaged_zipfile(self):
+ """Check that zipfiles with missing bytes at the end raise BadZipFile."""
+ # - Create a valid zip file
+ fp = io.BytesIO()
+ with zipfile.ZipFile(fp, mode="w") as zipf:
+ zipf.writestr("foo.txt", b"O, for a Muse of Fire!")
+ zipfiledata = fp.getvalue()
+
+ # - Now create copies of it missing the last N bytes and make sure
+ # a BadZipFile exception is raised when we try to open it
+ for N in range(len(zipfiledata)):
+ fp = io.BytesIO(zipfiledata[:N])
+ self.assertRaises(zipfile.BadZipFile, zipfile.ZipFile, fp)
+
def test_is_zip_valid_file(self):
"""Check that is_zipfile() correctly identifies zip files."""
# - passing a filename