]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
#19395: Raise exception when pickling a (BZ2|LZMA)(Compressor|Decompressor).
authorNadeem Vawda <nadeem.vawda@gmail.com>
Mon, 28 Oct 2013 20:41:24 +0000 (21:41 +0100)
committerNadeem Vawda <nadeem.vawda@gmail.com>
Mon, 28 Oct 2013 20:41:24 +0000 (21:41 +0100)
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.

1  2 
Lib/test/test_bz2.py
Lib/test/test_lzma.py
Modules/_bz2module.c
Modules/_lzmamodule.c

Simple merge
Simple merge
index abc4d5d732bcbbb0408c4fcad34f210d9b1b1354,3f7a6cf026202be84265d2565d61968cfa6aecdd..fd05de0a27c65b7307dbb3a50f154cf2ee47097a
@@@ -248,24 -250,14 +248,32 @@@ BZ2Compressor_flush(BZ2Compressor *self
      return result;
  }
  
+ static PyObject *
+ BZ2Compressor_getstate(BZ2Compressor *self, PyObject *noargs)
+ {
+     PyErr_Format(PyExc_TypeError, "cannot serialize '%s' object",
+                  Py_TYPE(self)->tp_name);
+     return NULL;
+ }
 +static void*
 +BZ2_Malloc(void* ctx, int items, int size)
 +{
 +    if (items < 0 || size < 0)
 +        return NULL;
 +    if ((size_t)items > (size_t)PY_SSIZE_T_MAX / (size_t)size)
 +        return NULL;
 +    /* PyMem_Malloc() cannot be used: compress() and decompress()
 +       release the GIL */
 +    return PyMem_RawMalloc(items * size);
 +}
 +
 +static void
 +BZ2_Free(void* ctx, void *ptr)
 +{
 +    PyMem_RawFree(ptr);
 +}
 +
  static int
  BZ2Compressor_init(BZ2Compressor *self, PyObject *args, PyObject *kwargs)
  {
Simple merge