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

Skip to content

Commit fc6e8aa

Browse files
#15546: Fix GzipFile.peek()'s handling of pathological input data.
This is a backport of changeset 8c07ff7f882f.
1 parent f186911 commit fc6e8aa

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

Lib/gzip.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,10 @@ def peek(self, n):
367367
if self.fileobj is None:
368368
return b''
369369
try:
370-
# 1024 is the same buffering heuristic used in read()
371-
self._read(max(n, 1024))
370+
# Ensure that we don't return b"" if we haven't reached EOF.
371+
while self.extrasize == 0:
372+
# 1024 is the same buffering heuristic used in read()
373+
self._read(max(n, 1024))
372374
except EOFError:
373375
pass
374376
offset = self.offset - self.extrastart

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,9 @@ Library
466466
- Issue #15424: Add a __sizeof__ implementation for array objects.
467467
Patch by Ludwig Hähne.
468468

469+
- Issue #15546: Fix handling of pathological input data in the peek() method
470+
of the GzipFile class.
471+
469472
- Issue #13052: Fix IDLE crashing when replace string in Search/Replace dialog
470473
ended with '\'. Patch by Roger Serwy.
471474

0 commit comments

Comments
 (0)