]> granicus.if.org Git - python/commitdiff
Close #17666: Fix reading gzip files with an extra field.
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 8 Apr 2013 19:35:02 +0000 (22:35 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Mon, 8 Apr 2013 19:35:02 +0000 (22:35 +0300)
Lib/gzip.py
Lib/test/test_gzip.py
Misc/NEWS

index 8fb1ed06c9d043e285859cbf097578ef3f74b107..0adfd3fdf8ae78424cec5d3b6cbb5b6c0fc9a6b3 100644 (file)
@@ -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:
index ba9d7dac8b09872611ff919a96e4fe0dbaaab1fa..b912576bcc08503ac8d38f25a9763afe5022a14d 100644 (file)
@@ -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)
index 115b287b5861956dc636ebdaeb16994e90d81cfc..e3e203f9b520b994bdd559447b293af5d153923e 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -2,18 +2,29 @@
 Python News
 +++++++++++
 
-What's New in Python 3.2.4?
+What's New in Python 3.2.5?
 ===========================
 
-*Release date: 07-Apr-2013*
+*Release date: 13-May-2013*
 
 Library
 -------
 
 - Issue #17192: Restore the patch for Issue #11729 and Issue #10309
-  which were ommitted in 3.2.4 when updating the bundled version of
+  which were omitted in 3.2.4 when updating the bundled version of
   libffi used by ctypes.
 
+- Issue #17666: Fix reading gzip files with an extra field.
+
+
+What's New in Python 3.2.4?
+===========================
+
+*Release date: 07-Apr-2013*
+
+Library
+-------
+
 - Issue #17625: In IDLE, close the replace dialog after it is used.