]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-137571: Protect against possible UnboundLocalError in gzip._GzipReader... 3.13
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 22 May 2026 09:37:57 +0000 (11:37 +0200)
committerGitHub <noreply@github.com>
Fri, 22 May 2026 09:37:57 +0000 (09:37 +0000)
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 <storchaka@gmail.com>
Lib/gzip.py

index a550c20a7a08baffd871632c6683bf425a6360fe..959c3cb58fdcd332cf7b017bce21f1d99b64b60a 100644 (file)
@@ -551,10 +551,10 @@ class _GzipReader(_compression.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()