[Python-checkins] r74246 - in python/branches/py3k: Lib/test/test_zipfile.py Lib/zipfile.py Misc/NEWS
amaury.forgeotdarc
python-checkins at python.org
Wed Jul 29 00:18:58 CEST 2009
Author: amaury.forgeotdarc
Date: Wed Jul 29 00:18:57 2009
New Revision: 74246
Log:
Merged revisions 74245 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74245 | amaury.forgeotdarc | 2009-07-29 00:15:30 +0200 (mer., 29 juil. 2009) | 3 lines
#6511: ZipFile will now raise BadZipfile when opening an empty or tiny file,
like it does for larger invalid files.
........
Modified:
python/branches/py3k/ (props changed)
python/branches/py3k/Lib/test/test_zipfile.py
python/branches/py3k/Lib/zipfile.py
python/branches/py3k/Misc/NEWS
Modified: python/branches/py3k/Lib/test/test_zipfile.py
==============================================================================
--- python/branches/py3k/Lib/test/test_zipfile.py (original)
+++ python/branches/py3k/Lib/test/test_zipfile.py Wed Jul 29 00:18:57 2009
@@ -701,6 +701,16 @@
# quickly.
self.assertRaises(IOError, zipfile.ZipFile, TESTFN)
+ def test_empty_file_raises_BadZipFile(self):
+ f = open(TESTFN, 'w')
+ f.close()
+ self.assertRaises(zipfile.BadZipfile, zipfile.ZipFile, TESTFN)
+
+ f = open(TESTFN, 'w')
+ f.write("short file")
+ f.close()
+ self.assertRaises(zipfile.BadZipfile, zipfile.ZipFile, TESTFN)
+
def test_closed_zip_raises_RuntimeError(self):
# Verify that testzip() doesn't swallow inappropriate exceptions.
data = io.BytesIO()
Modified: python/branches/py3k/Lib/zipfile.py
==============================================================================
--- python/branches/py3k/Lib/zipfile.py (original)
+++ python/branches/py3k/Lib/zipfile.py Wed Jul 29 00:18:57 2009
@@ -200,7 +200,10 @@
# Check to see if this is ZIP file with no archive comment (the
# "end of central directory" structure should be the last item in the
# file if this is the case).
- fpin.seek(-sizeEndCentDir, 2)
+ try:
+ fpin.seek(-sizeEndCentDir, 2)
+ except IOError:
+ return None
data = fpin.read()
if data[0:4] == stringEndArchive and data[-2:] == b"\000\000":
# the signature is correct and there's no comment, unpack structure
Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS (original)
+++ python/branches/py3k/Misc/NEWS Wed Jul 29 00:18:57 2009
@@ -956,7 +956,10 @@
Library
-------
-- Issue #6545: Removed assert statements in distutils.Extension, so the
+- Issue #6511: ZipFile now raises BadZipfile (instead of an IOError) when
+ opening an empty or very small file.
+
+- Issue #6545: Removed assert statements in distutils.Extension, so the
behavior is similar when used with -O.
- unittest has been split up into a package. All old names should still work.
More information about the Python-checkins
mailing list