Skip to content

Commit 8f7937e

Browse files
serhiy-storchakamiss-islington
authored andcommitted
gh-137571: Protect against possible UnboundLocalError in gzip._GzipReader.read() (GH-150222)
This has not been observed in practice, but we cannot be 100% sure that it will not happen with some weird gzip data. (cherry picked from commit 28eac9a) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent 954dd2f commit 8f7937e

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

Lib/gzip.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,10 +575,10 @@ def read(self, size=-1):
575575
# Read a chunk of data from the file
576576
if self._decompressor.needs_input:
577577
buf = self._fp.read(READ_BUFFER_SIZE)
578-
uncompress = self._decompressor.decompress(buf, size)
579578
else:
580-
uncompress = self._decompressor.decompress(b"", size)
579+
buf = b""
581580

581+
uncompress = self._decompressor.decompress(buf, size)
582582
if self._decompressor.unused_data != b"":
583583
# Prepend the already read bytes to the fileobj so they can
584584
# be seen by _read_eof() and _read_gzip_header()

0 commit comments

Comments
 (0)