diff options
author | Nadeem Vawda <nadeem.vawda@gmail.com> | 2013-12-04 22:29:51 (GMT) |
---|---|---|
committer | Nadeem Vawda <nadeem.vawda@gmail.com> | 2013-12-04 22:29:51 (GMT) |
commit | ae02d07bc2939f2f9e7a82543be3bb832ad8b29d (patch) | |
tree | 07ebcbf83fc7170a47c95677d76e7febe5837091 /Lib/test/test_lzma.py | |
parent | f9c54944dfe2f2594748a0a92938e4765c0c5900 (diff) | |
parent | 9c72ebc96be44c4ff66832cbe5e131065ae9d95d (diff) | |
download | cpython-ae02d07bc2939f2f9e7a82543be3bb832ad8b29d.zip cpython-ae02d07bc2939f2f9e7a82543be3bb832ad8b29d.tar.gz cpython-ae02d07bc2939f2f9e7a82543be3bb832ad8b29d.tar.bz2 |
Closes #19839: Fix regression in bz2 module's handling of non-bzip2 data at EOF.
Also fix an analogous bug (not a regression) in the lzma module.
Diffstat (limited to 'Lib/test/test_lzma.py')
-rw-r--r-- | Lib/test/test_lzma.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/test/test_lzma.py b/Lib/test/test_lzma.py index 26d19da..3e73d7f 100644 --- a/Lib/test/test_lzma.py +++ b/Lib/test/test_lzma.py @@ -314,6 +314,8 @@ class CompressDecompressFunctionTestCase(unittest.TestCase): def test_decompress_bad_input(self): with self.assertRaises(LZMAError): + lzma.decompress(COMPRESSED_BOGUS) + with self.assertRaises(LZMAError): lzma.decompress(COMPRESSED_RAW_1) with self.assertRaises(LZMAError): lzma.decompress(COMPRESSED_ALONE, format=lzma.FORMAT_XZ) @@ -348,6 +350,16 @@ class CompressDecompressFunctionTestCase(unittest.TestCase): ddata = lzma.decompress(COMPRESSED_XZ + COMPRESSED_ALONE) self.assertEqual(ddata, INPUT * 2) + # Test robust handling of non-LZMA data following the compressed stream(s). + + def test_decompress_trailing_junk(self): + ddata = lzma.decompress(COMPRESSED_XZ + COMPRESSED_BOGUS) + self.assertEqual(ddata, INPUT) + + def test_decompress_multistream_trailing_junk(self): + ddata = lzma.decompress(COMPRESSED_XZ * 3 + COMPRESSED_BOGUS) + self.assertEqual(ddata, INPUT * 3) + class TempFile: """Context manager - creates a file, and deletes it on __exit__.""" @@ -676,6 +688,14 @@ class FileTestCase(unittest.TestCase): finally: lzma._BUFFER_SIZE = saved_buffer_size + def test_read_trailing_junk(self): + with LZMAFile(BytesIO(COMPRESSED_XZ + COMPRESSED_BOGUS)) as f: + self.assertEqual(f.read(), INPUT) + + def test_read_multistream_trailing_junk(self): + with LZMAFile(BytesIO(COMPRESSED_XZ * 5 + COMPRESSED_BOGUS)) as f: + self.assertEqual(f.read(), INPUT * 5) + def test_read_from_file(self): with TempFile(TESTFN, COMPRESSED_XZ): with LZMAFile(TESTFN) as f: @@ -719,6 +739,10 @@ class FileTestCase(unittest.TestCase): with LZMAFile(BytesIO(COMPRESSED_XZ)) as f: self.assertRaises(TypeError, f.read, None) + def test_read_bad_data(self): + with LZMAFile(BytesIO(COMPRESSED_BOGUS)) as f: + self.assertRaises(LZMAError, f.read) + def test_read1(self): with LZMAFile(BytesIO(COMPRESSED_XZ)) as f: blocks = [] @@ -1232,6 +1256,8 @@ LAERTES Farewell. """ +COMPRESSED_BOGUS = b"this is not a valid lzma stream" + COMPRESSED_XZ = ( b"\xfd7zXZ\x00\x00\x04\xe6\xd6\xb4F\x02\x00!\x01\x16\x00\x00\x00t/\xe5\xa3" b"\xe0\x07\x80\x03\xdf]\x00\x05\x14\x07bX\x19\xcd\xddn\x98\x15\xe4\xb4\x9d" |