From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Fri, 22 May 2026 09:46:05 +0000 (+0200) Subject: [3.14] gh-137571: Protect against possible UnboundLocalError in gzip._GzipReader... X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=58a3681fd22a53c1833c885a7d9d47c8d54cba6a;p=thirdparty%2FPython%2Fcpython.git [3.14] gh-137571: Protect against possible UnboundLocalError in gzip._GzipReader.read() (GH-150222) (GH-150230) 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 28eac9a7263ad8dcfa9b536aa238549131857e0f) Co-authored-by: Serhiy Storchaka --- diff --git a/Lib/gzip.py b/Lib/gzip.py index c00f51858de0..7514ad5bf24f 100644 --- a/Lib/gzip.py +++ b/Lib/gzip.py @@ -575,10 +575,10 @@ class _GzipReader(_streams.DecompressReader): # 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()