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: gzip shouldn't ValueError on corruptfile
Type: Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: akuchling Nosy List: akuchling, donut
Priority: normal Keywords: patch

Created on 2002-12-16 06:39 by donut, last changed 2022-04-10 16:06 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
gzip.py.ValueError.patch donut, 2002-12-16 06:40 replace ValueError with IOError on corrupt files
Messages (3)
msg42005 - (view) Author: Matthew Mueller (donut) Date: 2002-12-16 06:39
Currently the gzip module will raise a ValueError if
the file was corrupt (bad crc or bad size), but this is
IMHO bad because it means you can't substitute a
GzipFile for a regular file without the risk of
exceptions breaking out of the code.  (And you don't
want to catch ValueError since it might hide coding
errors).

The docs say ValueError is "Raised when a built-in
operation or function receives an argument that has the
right type but an inappropriate value, and the
situation is not described by a more precise exception
such as IndexError".

I can't see how that applies to reading a corrupt file.
 IOError is probably the correct exception, because it
is what code will already be looking for, and because
even if technically there wasn't an actual io error,
from the point of view of the code, trying to read a
corrupt file is like an io error.
msg42006 - (view) Author: Matthew Mueller (donut) Date: 2002-12-16 06:40
Logged In: YES 
user_id=65253

Remembered to click the checkbox for attaching a file.
msg42007 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2003-02-05 21:41
Logged In: YES 
user_id=11375

I'll buy that logic.  Checked in as rev. 1.38 of gzip.py.
History
Date User Action Args
2022-04-10 16:06:02adminsetgithub: 37615
2002-12-16 06:39:23donutcreate