From 0ff3d95b9875805ac03aeffc37ae4458ce3b8ac0 Mon Sep 17 00:00:00 2001 From: Ruben Vorderman Date: Fri, 19 Nov 2021 19:07:05 +0100 Subject: bpo-45507: EOFErrors should be thrown for truncated gzip members (GH-29029) --- Lib/gzip.py | 3 +++ Lib/test/test_gzip.py | 8 ++++++++ Misc/NEWS.d/next/Library/2021-10-18-14-00-01.bpo-45507.lDotNV.rst | 1 + 3 files changed, 12 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2021-10-18-14-00-01.bpo-45507.lDotNV.rst diff --git a/Lib/gzip.py b/Lib/gzip.py index ac17810..6773ea3 100644 --- a/Lib/gzip.py +++ b/Lib/gzip.py @@ -603,6 +603,9 @@ def decompress(data): do = zlib.decompressobj(wbits=-zlib.MAX_WBITS) # Read all the data except the header decompressed = do.decompress(data[fp.tell():]) + if not do.eof or len(do.unused_data) < 8: + raise EOFError("Compressed file ended before the end-of-stream " + "marker was reached") crc, length = struct.unpack("