https://github.com/python/cpython/commit/e192a0ea521cdeac1531ddefb08df0db76c0207f commit: e192a0ea521cdeac1531ddefb08df0db76c0207f branch: 3.15 author: Miss Islington (bot) <[email protected]> committer: serhiy-storchaka <[email protected]> date: 2026-05-22T09:46:14Z summary:
[3.15] gh-137571: Protect against possible UnboundLocalError in gzip._GzipReader.read() (GH-150222) (GH-150229) 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 <[email protected]> files: M Lib/gzip.py diff --git a/Lib/gzip.py b/Lib/gzip.py index 8720acc4db9976..0713b922522ee1 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() _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
