[issue33173] GzipFile's .seekable() returns True even if underlying buffer is not seekable

Walt Askew report at bugs.python.org
Wed Mar 28 12:28:48 EDT 2018


New submission from Walt Askew <waltaskew at gmail.com>:

The seekable method on gzip.GzipFile always returns True, even if the underlying buffer is not seekable. However, if seek is called on the GzipFile, the seek will fail unless the underlying buffer is seekable. This can cause consumers of the GzipFile object to mistakenly believe calling seek on the object is safe, when in fact it will lead to an exception.

For example, this led to a bug when I was trying to use requests & boto3 to stream & decompress an S3 upload like so:

resp = requests.get(uri, stream=True)
decompressed = gzip.GzipFile(fileobj=resp.raw)
boto3.client('s3').upload_fileobj(decompressed, Bucket=bucket, Key=key)

boto3 checks the seekable method on the the GzipFile, chooses a code path based on the file being seekable but later raises an exception when the seek call fails because the underlying HTTP stream is not seekable.

----------
components: Library (Lib)
messages: 314613
nosy: Walt Askew
priority: normal
severity: normal
status: open
title: GzipFile's .seekable() returns True even if underlying buffer is not seekable
versions: Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33173>
_______________________________________


More information about the Python-bugs-list mailing list