diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2002-08-04 08:20:23 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2002-08-04 08:20:23 (GMT) |
commit | 5a3953027433f1928314af6cbb1be215357b55ad (patch) | |
tree | bb6819c089f528cb124b2457165e0e4c8d48d032 /Modules/cPickle.c | |
parent | 161ad0e16bf6a6ffbf191272f653ec38ccf131f9 (diff) | |
download | cpython-5a3953027433f1928314af6cbb1be215357b55ad.zip cpython-5a3953027433f1928314af6cbb1be215357b55ad.tar.gz cpython-5a3953027433f1928314af6cbb1be215357b55ad.tar.bz2 |
Add recursion counter for pickling. Fixes #576084.
2.2 bugfix candidate (may cause RuntimeError for applications that
currently work fine).
Diffstat (limited to 'Modules/cPickle.c')
-rw-r--r-- | Modules/cPickle.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Modules/cPickle.c b/Modules/cPickle.c index f8d9af8..b7b32c8 100644 --- a/Modules/cPickle.c +++ b/Modules/cPickle.c @@ -276,6 +276,7 @@ typedef struct Picklerobject { PyObject *inst_pers_func; int bin; int fast; /* Fast mode doesn't save in memo, don't use if circ ref */ + int nesting; int (*write_func)(struct Picklerobject *, char *, int); char *write_buf; int buf_size; @@ -1867,6 +1868,12 @@ save(Picklerobject *self, PyObject *args, int pers_save) *callable = 0, *state = 0; 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 ((tmp = save_pers(self, args, self->pers_func)) != 0) { res = tmp; @@ -2092,6 +2099,7 @@ save(Picklerobject *self, PyObject *args, int pers_save) PyErr_SetObject(UnpickleableError, args); finally: + self->nesting--; Py_XDECREF(py_ob_id); Py_XDECREF(__reduce__); Py_XDECREF(t); @@ -2314,6 +2322,7 @@ newPicklerobject(PyObject *file, int bin) self->write_buf = NULL; self->bin = bin; self->fast = 0; + self->nesting = 0; self->fast_container = 0; self->fast_memo = NULL; self->buf_size = 0; |