summaryrefslogtreecommitdiff
path: root/Lib/gzip.py
diff options
context:
space:
mode:
authorRuben Vorderman <r.h.p.vorderman@lumc.nl>2021-11-19 19:07:05 +0100
committerGitHub <noreply@github.com>2021-11-19 19:07:05 +0100
commit0ff3d95b9875805ac03aeffc37ae4458ce3b8ac0 (patch)
tree6f82877c128a0bab19926e8fe4b3a9d7eb3716b2 /Lib/gzip.py
parent7e44dc0ba768451f287a541cd1c85f7d87a41561 (diff)
downloadcpython-git-0ff3d95b9875805ac03aeffc37ae4458ce3b8ac0.tar.gz
bpo-45507: EOFErrors should be thrown for truncated gzip members (GH-29029)
Diffstat (limited to 'Lib/gzip.py')
-rw-r--r--Lib/gzip.py3
1 files changed, 3 insertions, 0 deletions
diff --git a/Lib/gzip.py b/Lib/gzip.py
index ac1781042b..6773ea3eef 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("<II", do.unused_data[:8])
if crc != zlib.crc32(decompressed):
raise BadGzipFile("CRC check failed")