From 67db028a3259bb34b9fbfe78acbca17c70f8f051 Mon Sep 17 00:00:00 2001 From: maurycy <5383+maurycy@users.noreply.github.com> Date: Sat, 9 Aug 2025 00:59:56 +0200 Subject: [PATCH] `buf` exists iff `self._decompressor.needs_input` --- Lib/gzip.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Lib/gzip.py b/Lib/gzip.py index 89c4738ec69325..018859b25e5a24 100644 --- a/Lib/gzip.py +++ b/Lib/gzip.py @@ -575,6 +575,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) + if buf == b"": + raise EOFError("Compressed file ended before the " + "end-of-stream marker was reached") + uncompress = self._decompressor.decompress(buf, size) else: uncompress = self._decompressor.decompress(b"", size) @@ -586,9 +590,6 @@ def read(self, size=-1): if uncompress != b"": break - if buf == b"": - raise EOFError("Compressed file ended before the " - "end-of-stream marker was reached") self._crc = zlib.crc32(uncompress, self._crc) self._stream_size += len(uncompress)