From 67b4020acb9a4043455f5e9b1afa8dfd5ac7aaa1 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Fri, 22 May 2026 10:37:51 +0300 Subject: [PATCH] gh-137571: Protect agains possible UnboundLocalError in gzip._GzipReader.read() This has not been observed in practice, but we cannot be 100% sure that it will not happen with some weird gzip data. --- Lib/gzip.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/gzip.py b/Lib/gzip.py index 8720acc4db99762..0713b922522ee18 100644 --- a/Lib/gzip.py +++ b/Lib/gzip.py @@ -610,10 +610,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) - uncompress = self._decompressor.decompress(buf, size) else: - uncompress = self._decompressor.decompress(b"", size) + buf = b"" + uncompress = self._decompressor.decompress(buf, size) if self._decompressor.unused_data != b"": # Prepend the already read bytes to the fileobj so they can # be seen by _read_eof() and _read_gzip_header()