Title: GzipFile's .seekable() returns True even if underlying buffer is not seekable
Type: Stage: patch review
Components: Library (Lib) Versions: Python 3.6
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Walt Askew, xtreak
Priority: normal Keywords: patch

Created on 2018-03-28 16:28 by Walt Askew, last changed 2018-09-14 08:39 by xtreak.

Pull Requests
URL Status Linked Edit
PR 6303 open python-dev, 2018-03-28 23:46
Messages (1)
msg314613 - (view) Author: Walt Askew (Walt Askew) Date: 2018-03-28 16:28
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.
Date User Action Args
2018-09-14 08:39:14xtreaksetnosy: + xtreak
2018-03-28 23:46:24python-devsetkeywords: + patch
stage: patch review
pull_requests: + pull_request6021
2018-03-28 16:28:47Walt Askewcreate