mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Close #17666: Fix reading gzip files with an extra field.
This commit is contained in:
commit
ffcd339aac
3 changed files with 11 additions and 1 deletions
|
@ -302,7 +302,8 @@ class GzipFile(io.BufferedIOBase):
|
||||||
|
|
||||||
if flag & FEXTRA:
|
if flag & FEXTRA:
|
||||||
# Read & discard the extra field, if present
|
# Read & discard the extra field, if present
|
||||||
self._read_exact(struct.unpack("<H", self._read_exact(2)))
|
extra_len, = struct.unpack("<H", self._read_exact(2))
|
||||||
|
self._read_exact(extra_len)
|
||||||
if flag & FNAME:
|
if flag & FNAME:
|
||||||
# Read and discard a null-terminated string containing the filename
|
# Read and discard a null-terminated string containing the filename
|
||||||
while True:
|
while True:
|
||||||
|
|
|
@ -403,6 +403,13 @@ class TestGzip(BaseTest):
|
||||||
with gzip.GzipFile(fileobj=io.BytesIO(truncated[:i])) as f:
|
with gzip.GzipFile(fileobj=io.BytesIO(truncated[:i])) as f:
|
||||||
self.assertRaises(EOFError, f.read, 1)
|
self.assertRaises(EOFError, f.read, 1)
|
||||||
|
|
||||||
|
def test_read_with_extra(self):
|
||||||
|
# Gzip data with an extra field
|
||||||
|
gzdata = (b'\x1f\x8b\x08\x04\xb2\x17cQ\x02\xff'
|
||||||
|
b'\x05\x00Extra'
|
||||||
|
b'\x0bI-.\x01\x002\xd1Mx\x04\x00\x00\x00')
|
||||||
|
with gzip.GzipFile(fileobj=io.BytesIO(gzdata)) as f:
|
||||||
|
self.assertEqual(f.read(), b'Test')
|
||||||
|
|
||||||
class TestOpen(BaseTest):
|
class TestOpen(BaseTest):
|
||||||
def test_binary_modes(self):
|
def test_binary_modes(self):
|
||||||
|
|
|
@ -30,6 +30,8 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #17666: Fix reading gzip files with an extra field.
|
||||||
|
|
||||||
- Issue #16475: Support object instancing, recursion and interned strings
|
- Issue #16475: Support object instancing, recursion and interned strings
|
||||||
in marshal
|
in marshal
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue