]> granicus.if.org Git - python/commitdiff
#15546: Fix GzipFile.peek()'s handling of pathological input data.
authorSerhiy Storchaka <storchaka@gmail.com>
Tue, 22 Jan 2013 13:54:48 +0000 (15:54 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Tue, 22 Jan 2013 13:54:48 +0000 (15:54 +0200)
This is a backport of changeset 8c07ff7f882f.

Lib/gzip.py
Misc/NEWS

index 403040bd9c4832e9e839185cd023c36b8d6c3df2..6aacc9a4f96c7480bdf8318cda419a03872e6001 100644 (file)
@@ -367,8 +367,10 @@ class GzipFile(io.BufferedIOBase):
             if self.fileobj is None:
                 return b''
             try:
-                # 1024 is the same buffering heuristic used in read()
-                self._read(max(n, 1024))
+                # Ensure that we don't return b"" if we haven't reached EOF.
+                while self.extrasize == 0:
+                    # 1024 is the same buffering heuristic used in read()
+                    self._read(max(n, 1024))
             except EOFError:
                 pass
         offset = self.offset - self.extrastart
index a46bcc7183cc7ef5134c6f8a33d01dcc29588b56..c5cbdecab1c0724bb68952a5651cf7868b1d7e82 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -466,6 +466,9 @@ Library
 - Issue #15424: Add a __sizeof__ implementation for array objects.
   Patch by Ludwig Hähne.
 
+- Issue #15546: Fix handling of pathological input data in the peek() method
+  of the GzipFile class.
+
 - Issue #13052: Fix IDLE crashing when replace string in Search/Replace dialog
   ended with '\'. Patch by Roger Serwy.