Skip to content

gh-137571: Fix UnboundLocalError in gzip._GzipReader.read() #137572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
buf exists iff self._decompressor.needs_input
  • Loading branch information
maurycy committed Aug 8, 2025
commit 67db028a3259bb34b9fbfe78acbca17c70f8f051
7 changes: 4 additions & 3 deletions Lib/gzip.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,10 @@ def read(self, size=-1):
# Read a chunk of data from the file
if self._decompressor.needs_input:
buf = self._fp.read(READ_BUFFER_SIZE)
if buf == b"":
raise EOFError("Compressed file ended before the "
"end-of-stream marker was reached")

uncompress = self._decompressor.decompress(buf, size)
else:
uncompress = self._decompressor.decompress(b"", size)
Expand All @@ -586,9 +590,6 @@ def read(self, size=-1):

if uncompress != b"":
break
if buf == b"":
raise EOFError("Compressed file ended before the "
"end-of-stream marker was reached")

self._crc = zlib.crc32(uncompress, self._crc)
self._stream_size += len(uncompress)
Expand Down
Loading