[issue1159051] Handle corrupted gzip files with unexpected EOF

Wummel report at bugs.python.org
Thu Oct 25 22:58:44 CEST 2007


Wummel added the comment:

Here is a new test script that works with simple strings and no file
objects. It reproduces the error by cutting off the last two bytes of
the GZIP data.

The resulting struct error is due to the read() methods missing a check
that the requested amount of data is actually returned. In this case
read(4) returned 2 bytes instead of 4, and the struct raises an error.

I think the easiest way to handle this is to introduce a
read_save(fileobj, size) method that checks that the read() data is of
the requested size, else raise an error (perhaps an IOError?).

btw: you can remove the t.{gz,py} files, the test_gzip_error.py replaces
them.

Added file: http://bugs.python.org/file8610/test_gzip_error.py

_____________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1159051>
_____________________________________
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_gzip_error.py
Type: text/x-python
Size: 413 bytes
Desc: not available
Url : http://mail.python.org/pipermail/python-bugs-list/attachments/20071025/18596e86/attachment.py 


More information about the Python-bugs-list mailing list