summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/gzip.py3
-rw-r--r--Lib/test/test_gzip.py7
2 files changed, 9 insertions, 1 deletions
diff --git a/Lib/gzip.py b/Lib/gzip.py
index 8fb1ed0..0adfd3f 100644
--- a/Lib/gzip.py
+++ b/Lib/gzip.py
@@ -280,7 +280,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 ba9d7da..b912576 100644
--- a/Lib/test/test_gzip.py
+++ b/Lib/test/test_gzip.py
@@ -379,6 +379,13 @@ class TestGzip(unittest.TestCase):
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')
def test_main(verbose=None):
support.run_unittest(TestGzip)