Skip to content

Commit b7a6f43

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 1df755c commit b7a6f43

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
@@ -551,10 +551,10 @@ def read(self, size=-1):
551551
# Read a chunk of data from the file
552552
if self._decompressor.needs_input:
553553
buf = self._fp.read(READ_BUFFER_SIZE)
554-
uncompress = self._decompressor.decompress(buf, size)
555554
else:
556-
uncompress = self._decompressor.decompress(b"", size)
555+
buf = b""
557556

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

0 commit comments

Comments
 (0)