mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
#19395: Raise exception when pickling a (BZ2|LZMA)(Compressor|Decompressor).
The underlying C libraries provide no mechanism for serializing compressor and decompressor objects, so actually pickling these classes is impractical. Previously, these objects would be pickled without error, but attempting to use a deserialized instance would segfault the interpreter.
This commit is contained in:
parent
ba4e58a021
commit
3797065ac5
5 changed files with 61 additions and 2 deletions
|
@ -5,6 +5,7 @@ from test.support import TESTFN, bigmemtest, _4G
|
|||
import unittest
|
||||
from io import BytesIO
|
||||
import os
|
||||
import pickle
|
||||
import random
|
||||
import subprocess
|
||||
import sys
|
||||
|
@ -621,6 +622,11 @@ class BZ2CompressorTest(BaseTest):
|
|||
finally:
|
||||
data = None
|
||||
|
||||
def testPickle(self):
|
||||
with self.assertRaises(TypeError):
|
||||
pickle.dumps(BZ2Compressor())
|
||||
|
||||
|
||||
class BZ2DecompressorTest(BaseTest):
|
||||
def test_Constructor(self):
|
||||
self.assertRaises(TypeError, BZ2Decompressor, 42)
|
||||
|
@ -672,6 +678,10 @@ class BZ2DecompressorTest(BaseTest):
|
|||
compressed = None
|
||||
decompressed = None
|
||||
|
||||
def testPickle(self):
|
||||
with self.assertRaises(TypeError):
|
||||
pickle.dumps(BZ2Decompressor())
|
||||
|
||||
|
||||
class CompressDecompressTest(BaseTest):
|
||||
def testCompress(self):
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from io import BytesIO, UnsupportedOperation
|
||||
import os
|
||||
import pickle
|
||||
import random
|
||||
import unittest
|
||||
|
||||
|
@ -216,6 +217,14 @@ class CompressorDecompressorTestCase(unittest.TestCase):
|
|||
finally:
|
||||
input = cdata = ddata = None
|
||||
|
||||
# Pickling raises an exception; there's no way to serialize an lzma_stream.
|
||||
|
||||
def test_pickle(self):
|
||||
with self.assertRaises(TypeError):
|
||||
pickle.dumps(LZMACompressor())
|
||||
with self.assertRaises(TypeError):
|
||||
pickle.dumps(LZMADecompressor())
|
||||
|
||||
|
||||
class CompressDecompressFunctionTestCase(unittest.TestCase):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue