diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-04-08 22:37:15 +0300 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-04-08 22:37:15 +0300 |
commit | ffcd339aac9380a03cc41a7684847443a1fb525e (patch) | |
tree | 04f57f79081c64d2ca21da6ff5c13299076c6c89 | |
parent | c137f7c065990cd438de3083ca4ade29000d57e2 (diff) | |
parent | 7e69f0085e5365347bf00f4ed08d07e5f4785a96 (diff) | |
download | cpython-git-ffcd339aac9380a03cc41a7684847443a1fb525e.tar.gz |
Close #17666: Fix reading gzip files with an extra field.
-rw-r--r-- | Lib/gzip.py | 3 | ||||
-rw-r--r-- | Lib/test/test_gzip.py | 7 | ||||
-rw-r--r-- | Misc/NEWS | 2 |
3 files changed, 11 insertions, 1 deletions
diff --git a/Lib/gzip.py b/Lib/gzip.py index d5b5743ff6..d2d6dd6531 100644 --- a/Lib/gzip.py +++ b/Lib/gzip.py @@ -302,7 +302,8 @@ class GzipFile(io.BufferedIOBase): if flag & FEXTRA: # 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: # Read and discard a null-terminated string containing the filename while True: diff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.py index ebd4c43855..37fe8538a7 100644 --- a/Lib/test/test_gzip.py +++ b/Lib/test/test_gzip.py @@ -403,6 +403,13 @@ class TestGzip(BaseTest): with gzip.GzipFile(fileobj=io.BytesIO(truncated[:i])) as f: 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): def test_binary_modes(self): @@ -30,6 +30,8 @@ Core and Builtins Library ------- +- Issue #17666: Fix reading gzip files with an extra field. + - Issue #16475: Support object instancing, recursion and interned strings in marshal |