mirror of
https://github.com/python/cpython.git
synced 2025-11-01 02:38:53 +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
|
|
@ -669,6 +669,20 @@ class FileTestCase(unittest.TestCase):
|
|||
with LZMAFile(BytesIO(COMPRESSED_XZ[:128])) as f:
|
||||
self.assertRaises(EOFError, f.read)
|
||||
|
||||
def test_read_truncated(self):
|
||||
# Drop stream footer: CRC (4 bytes), index size (4 bytes),
|
||||
# flags (2 bytes) and magic number (2 bytes).
|
||||
truncated = COMPRESSED_XZ[:-12]
|
||||
with LZMAFile(BytesIO(truncated)) as f:
|
||||
self.assertRaises(EOFError, f.read)
|
||||
with LZMAFile(BytesIO(truncated)) as f:
|
||||
self.assertEqual(f.read(len(INPUT)), INPUT)
|
||||
self.assertRaises(EOFError, f.read, 1)
|
||||
# Incomplete 12-byte header.
|
||||
for i in range(12):
|
||||
with LZMAFile(BytesIO(truncated[:i])) as f:
|
||||
self.assertRaises(EOFError, f.read, 1)
|
||||
|
||||
def test_read_bad_args(self):
|
||||
f = LZMAFile(BytesIO(COMPRESSED_XZ))
|
||||
f.close()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue