From 6230e9f2c5af5ec480f58cb5dc55d9c20a84bd09 Mon Sep 17 00:00:00 2001 From: Ruben Vorderman Date: Mon, 18 Oct 2021 14:00:35 +0200 Subject: [PATCH] EOFErrors should be thrown for truncated gzip members --- Lib/gzip.py | 3 +++ Lib/test/test_gzip.py | 8 ++++++++ .../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 0dddb51553fabd..27211eef0d63a2 100644 --- a/Lib/gzip.py +++ b/Lib/gzip.py @@ -607,6 +607,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("