[Patches] [ python-Patches-756996 ] Bare except in ZipFile.testzip()

SourceForge.net noreply@sourceforge.net
Fri, 27 Jun 2003 15:26:25 -0700


Patches item #756996, was opened at 2003-06-18 21:49
Message generated for change (Comment added) made by rhettinger
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=756996&group_id=5470

Category: Library (Lib)
Group: Python 2.3
>Status: Closed
>Resolution: Accepted
Priority: 5
Submitted By: Steven Taschuk (staschuk)
Assigned to: Raymond Hettinger (rhettinger)
Summary: Bare except in ZipFile.testzip()

Initial Comment:
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.)

----------------------------------------------------------------------

>Comment By: Raymond Hettinger (rhettinger)
Date: 2003-06-27 17:26

Message:
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

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=756996&group_id=5470