diff options
author | R. David Murray <rdmurray@bitdance.com> | 2010-01-06 20:08:02 (GMT) |
---|---|---|
committer | R. David Murray <rdmurray@bitdance.com> | 2010-01-06 20:08:02 (GMT) |
commit | 981130bf93b7576e9e7290cb0449b532b508e0c4 (patch) | |
tree | 0351e1c775d55c083118011fb56499f2a5dc8ddd /Lib | |
parent | 8b1587fd63ae3c783a772f86f63593d7f65bb6db (diff) | |
download | cpython-981130bf93b7576e9e7290cb0449b532b508e0c4.zip cpython-981130bf93b7576e9e7290cb0449b532b508e0c4.tar.gz cpython-981130bf93b7576e9e7290cb0449b532b508e0c4.tar.bz2 |
Merged revisions 74245 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74245 | amaury.forgeotdarc | 2009-07-28 18:15:30 -0400 (Tue, 28 Jul 2009) | 3 lines
#6511: ZipFile will now raise BadZipfile when opening an empty or tiny file,
like it does for larger invalid files.
........
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_zipfile.py | 10 | ||||
-rw-r--r-- | Lib/zipfile.py | 5 |
2 files changed, 14 insertions, 1 deletions
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py index 1fed79a..a2c3a2c 100644 --- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -664,6 +664,16 @@ class OtherTests(unittest.TestCase): # 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 = StringIO() diff --git a/Lib/zipfile.py b/Lib/zipfile.py index e2ede45..34b3f1a 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -186,7 +186,10 @@ def _EndRecData(fpin): # 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:] == "\000\000": # the signature is correct and there's no comment, unpack structure |