From: Serhiy Storchaka Date: Tue, 22 Jan 2013 15:11:07 +0000 (+0200) Subject: Issue #1159051: GzipFile now raises EOFError when reading a corrupted file X-Git-Tag: v3.4.0a1~1555 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cc0172c00704e8292c90e02e776b0c193ca75477;p=python Issue #1159051: GzipFile now raises EOFError when reading a corrupted file with truncated header or footer. Added tests for reading truncated gzip, bzip2, and lzma files. --- cc0172c00704e8292c90e02e776b0c193ca75477 diff --cc Lib/gzip.py index 698f0c2747,d7da02ca1b..d5b5743ff6 --- a/Lib/gzip.py +++ b/Lib/gzip.py @@@ -284,18 -291,14 +291,14 @@@ class GzipFile(io.BufferedIOBase) def _read_gzip_header(self): magic = self.fileobj.read(2) if magic == b'': - raise EOFError("Reached EOF") + return False if magic != b'\037\213': - raise IOError('Not a gzipped file') + raise OSError('Not a gzipped file') - method = ord( self.fileobj.read(1) ) + + method, flag, self.mtime = struct.unpack("