Irit Katriel <[email protected]> added the comment:
Reproduced on 3.11:
>>> from gzip import GzipFile
>>> from io import BytesIO
>>> file = BytesIO()
>>> with GzipFile(fileobj=file, mode="wb") as z:
... z.write(b"data")
...
4
>>> file.write(b"garbage")
7
>>> file.seek(0)
0
>>> GzipFile(fileobj=file).read()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/iritkatriel/src/cpython-654/Lib/gzip.py", line 301, in read
return self._buffer.read(size)
^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/iritkatriel/src/cpython-654/Lib/_compression.py", line 118, in
readall
while data := self.read(sys.maxsize):
^^^^^^^^^^^^^^^^^^^^^^
File "/Users/iritkatriel/src/cpython-654/Lib/gzip.py", line 499, in read
if not self._read_gzip_header():
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/iritkatriel/src/cpython-654/Lib/gzip.py", line 468, in
_read_gzip_header
last_mtime = _read_gzip_header(self._fp)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/iritkatriel/src/cpython-654/Lib/gzip.py", line 428, in
_read_gzip_header
raise BadGzipFile('Not a gzipped file (%r)' % magic)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
gzip.BadGzipFile: Not a gzipped file (b'ga')
----------
nosy: +iritkatriel
type: -> behavior
versions: +Python 3.10, Python 3.11, Python 3.9 -Python 3.4
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue24301>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com