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 <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1159051>
_____________________________________
# test corrupted GZIP data
import gzip
import StringIO

uncompressed = "This is a test"
fileobj = StringIO.StringIO()
gzipobj = gzip.GzipFile("test.gz", 'wb', 9, fileobj)
gzipobj.write(uncompressed)
gzipobj.close()
# corrupt the .gz data: remove the last 2 bytes
compressed = fileobj.getvalue()[:-2]
# now uncompress again
fileobj = StringIO.StringIO(compressed)
print gzip.GzipFile('', 'rb', 9, fileobj).read()

_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to