]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-137571: Protect against possible UnboundLocalError in gzip._GzipReader.read()...
authorSerhiy Storchaka <storchaka@gmail.com>
Fri, 22 May 2026 09:17:34 +0000 (12:17 +0300)
committerGitHub <noreply@github.com>
Fri, 22 May 2026 09:17:34 +0000 (12:17 +0300)
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

index 8720acc4db99762616fc20e16373a8a02005d8f8..0713b922522ee18439932b7e731fcc24b34a872e 100644 (file)
@@ -610,10 +610,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()