[Python-checkins] r77335 - in python/branches/release31-maint: Lib/test/test_zipfile.py Lib/zipfile.py Misc/NEWS
r.david.murray
python-checkins at python.org
Wed Jan 6 21:12:08 CET 2010
Author: r.david.murray
Date: Wed Jan 6 21:12:07 2010
New Revision: 77335
Log:
Merged revisions 74246 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r74246 | amaury.forgeotdarc | 2009-07-28 18:18:57 -0400 (Tue, 28 Jul 2009) | 10 lines
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/release31-maint/ (props changed)
python/branches/release31-maint/Lib/test/test_zipfile.py
python/branches/release31-maint/Lib/zipfile.py
python/branches/release31-maint/Misc/NEWS
Modified: python/branches/release31-maint/Lib/test/test_zipfile.py
==============================================================================
--- python/branches/release31-maint/Lib/test/test_zipfile.py (original)
+++ python/branches/release31-maint/Lib/test/test_zipfile.py Wed Jan 6 21:12:07 2010
@@ -688,6 +688,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 testClosedZipRaisesRuntimeError(self):
# Verify that testzip() doesn't swallow inappropriate exceptions.
data = io.BytesIO()
Modified: python/branches/release31-maint/Lib/zipfile.py
==============================================================================
--- python/branches/release31-maint/Lib/zipfile.py (original)
+++ python/branches/release31-maint/Lib/zipfile.py Wed Jan 6 21:12:07 2010
@@ -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/release31-maint/Misc/NEWS
==============================================================================
--- python/branches/release31-maint/Misc/NEWS (original)
+++ python/branches/release31-maint/Misc/NEWS Wed Jan 6 21:12:07 2010
@@ -61,6 +61,9 @@
Library
-------
+- Issue #6511: ZipFile now raises BadZipfile (instead of an IOError) when
+ opening an empty or very small file.
+
- Issue #7556: Make sure Distutils' msvc9compile reads and writes the
MSVC XML Manifest file in text mode so string patterns can be used
in regular expressions.
More information about the Python-checkins
mailing list