This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Bare except in ZipFile.testzip()
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: rhettinger, staschuk
Priority: normal Keywords: patch

Created on 2003-06-19 02:49 by staschuk, last changed 2022-04-10 16:09 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
zipfile-bare-except.patch staschuk, 2003-06-19 02:49
Messages (2)
msg44072 - (view) Author: Steven Taschuk (staschuk) Date: 2003-06-19 02:49
ZipFile.testzip tries to call self.read, and reports the first 
file in the archive for which this raises an exception.  
Since a bare except is used, way too many kinds of 
exception are caught.  This causes weirdness such as

>>> import zipfile
>>> z = zipfile.ZipFile('foo.zip')
>>> z.close()
>>> z.testzip()
'nt.to.png'

When the ZipFile has been closed, .read raises a 
RuntimeError; .testzip reports this as a problem with the 
first file in the archive, which is misleading in the 
extreme.  Propagating the RuntimeError would be better.

Similarly IOErrors while reading the file are swallowed, 
as are KeyboardInterrupts, SystemExits, RuntimeErrors 
due to the absence of zlib...

The patch changes the except clause to catch only 
BadZipfile, which is explicitly raised in .read for checksum 
failures.  The docs indicate that that's what .testzip tests.  
(This exception is also raised for unsupported 
compression methods.  I'm not sure how .testzip should 
treat those; perhaps the two conditions should have 
different exception types.)

(A different bare except in this module received attention 
in bug 411881.)
msg44073 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2003-06-27 22:26
Logged In: YES 
user_id=80475

Applied as:

/cvsroot/python/python/dist/src/Misc/NEWS 1.792
/cvsroot/python/python/dist/src/Lib/zipfile.py 1.31
/cvsroot/python/python/dist/src/Lib/test/test_zipfile.py 1.10
History
Date User Action Args
2022-04-10 16:09:20adminsetgithub: 38680
2003-06-19 02:49:38staschukcreate