mirror of
https://github.com/python/cpython.git
synced 2025-11-14 07:49:28 +00:00
Add recursion counter for pickling. Fixes #576084.
2.2 bugfix candidate (may cause RuntimeError for applications that currently work fine).
This commit is contained in:
parent
161ad0e16b
commit
5a39530274
1 changed files with 9 additions and 0 deletions
|
|
@ -276,6 +276,7 @@ typedef struct Picklerobject {
|
||||||
PyObject *inst_pers_func;
|
PyObject *inst_pers_func;
|
||||||
int bin;
|
int bin;
|
||||||
int fast; /* Fast mode doesn't save in memo, don't use if circ ref */
|
int fast; /* Fast mode doesn't save in memo, don't use if circ ref */
|
||||||
|
int nesting;
|
||||||
int (*write_func)(struct Picklerobject *, char *, int);
|
int (*write_func)(struct Picklerobject *, char *, int);
|
||||||
char *write_buf;
|
char *write_buf;
|
||||||
int buf_size;
|
int buf_size;
|
||||||
|
|
@ -1867,6 +1868,12 @@ save(Picklerobject *self, PyObject *args, int pers_save)
|
||||||
*callable = 0, *state = 0;
|
*callable = 0, *state = 0;
|
||||||
int res = -1, tmp, size;
|
int res = -1, tmp, size;
|
||||||
|
|
||||||
|
if (self->nesting++ > Py_GetRecursionLimit()){
|
||||||
|
PyErr_SetString(PyExc_RuntimeError,
|
||||||
|
"maximum recursion depth exceeded");
|
||||||
|
goto finally;
|
||||||
|
}
|
||||||
|
|
||||||
if (!pers_save && self->pers_func) {
|
if (!pers_save && self->pers_func) {
|
||||||
if ((tmp = save_pers(self, args, self->pers_func)) != 0) {
|
if ((tmp = save_pers(self, args, self->pers_func)) != 0) {
|
||||||
res = tmp;
|
res = tmp;
|
||||||
|
|
@ -2092,6 +2099,7 @@ save(Picklerobject *self, PyObject *args, int pers_save)
|
||||||
PyErr_SetObject(UnpickleableError, args);
|
PyErr_SetObject(UnpickleableError, args);
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
self->nesting--;
|
||||||
Py_XDECREF(py_ob_id);
|
Py_XDECREF(py_ob_id);
|
||||||
Py_XDECREF(__reduce__);
|
Py_XDECREF(__reduce__);
|
||||||
Py_XDECREF(t);
|
Py_XDECREF(t);
|
||||||
|
|
@ -2314,6 +2322,7 @@ newPicklerobject(PyObject *file, int bin)
|
||||||
self->write_buf = NULL;
|
self->write_buf = NULL;
|
||||||
self->bin = bin;
|
self->bin = bin;
|
||||||
self->fast = 0;
|
self->fast = 0;
|
||||||
|
self->nesting = 0;
|
||||||
self->fast_container = 0;
|
self->fast_container = 0;
|
||||||
self->fast_memo = NULL;
|
self->fast_memo = NULL;
|
||||||
self->buf_size = 0;
|
self->buf_size = 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue