Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0435400

Browse files
committed
python#15546: Also fix GzipFile.peek().
1 parent e3ded95 commit 0435400

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

Lib/gzip.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,10 @@ def peek(self, n):
413413
if self.fileobj is None:
414414
return b''
415415
try:
416-
# 1024 is the same buffering heuristic used in read()
417-
self._read(max(n, 1024))
416+
# Ensure that we don't return b"" if we haven't reached EOF.
417+
while self.extrasize == 0:
418+
# 1024 is the same buffering heuristic used in read()
419+
self._read(max(n, 1024))
418420
except EOFError:
419421
pass
420422
offset = self.offset - self.extrastart

Misc/NEWS

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ Library
8181
constructor, objects in the ipaddress module no longer implement __index__
8282
(they still implement __int__ as appropriate)
8383

84-
- Issue #15546: Fix handling of pathological input data in the read1() method of
85-
the BZ2File, GzipFile and LZMAFile classes.
84+
- Issue #15546: Fix handling of pathological input data in the peek() and
85+
read1() methods of the BZ2File, GzipFile and LZMAFile classes.
8686

8787
- Issue #13052: Fix IDLE crashing when replace string in Search/Replace dialog
8888
ended with '\'. Patch by Roger Serwy.

0 commit comments

Comments
 (0)