mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
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.
This commit is contained in:
commit
57f9b7a124
5 changed files with 82 additions and 44 deletions
|
@ -389,6 +389,20 @@ class TestGzip(BaseTest):
|
|||
datac = gzip.compress(data)
|
||||
self.assertEqual(gzip.decompress(datac), data)
|
||||
|
||||
def test_read_truncated(self):
|
||||
data = data1*50
|
||||
# Drop the CRC (4 bytes) and file size (4 bytes).
|
||||
truncated = gzip.compress(data)[:-8]
|
||||
with gzip.GzipFile(fileobj=io.BytesIO(truncated)) as f:
|
||||
self.assertRaises(EOFError, f.read)
|
||||
with gzip.GzipFile(fileobj=io.BytesIO(truncated)) as f:
|
||||
self.assertEqual(f.read(len(data)), data)
|
||||
self.assertRaises(EOFError, f.read, 1)
|
||||
# Incomplete 10-byte header.
|
||||
for i in range(2, 10):
|
||||
with gzip.GzipFile(fileobj=io.BytesIO(truncated[:i])) as f:
|
||||
self.assertRaises(EOFError, f.read, 1)
|
||||
|
||||
|
||||
class TestOpen(BaseTest):
|
||||
def test_binary_modes(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue