summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_lzma.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-01-22 15:07:49 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-01-22 15:07:49 (GMT)
commit57f9b7a12420d461e8ea5cc1ba63f80de778c7d5 (patch)
treec68dc61b4ff59cb81b20427786c4785c36472613 /Lib/test/test_lzma.py
parenta80f761a6d23f42abc529a338477741ba4973168 (diff)
parent7c3922f44c226eac29a497648bbc3cc8702905a8 (diff)
downloadcpython-57f9b7a12420d461e8ea5cc1ba63f80de778c7d5.zip
cpython-57f9b7a12420d461e8ea5cc1ba63f80de778c7d5.tar.gz
cpython-57f9b7a12420d461e8ea5cc1ba63f80de778c7d5.tar.bz2
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.
Diffstat (limited to 'Lib/test/test_lzma.py')
-rw-r--r--Lib/test/test_lzma.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_lzma.py b/Lib/test/test_lzma.py
index a13cf3b..4669ee2 100644
--- a/Lib/test/test_lzma.py
+++ b/Lib/test/test_lzma.py
@@ -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()