diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2011-05-10 22:02:56 (GMT) |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2011-05-10 22:02:56 (GMT) |
commit | 136726537ffd92b0f3e8dabb23023ed514852e2e (patch) | |
tree | c885de5f31a12d00d79c63915e0997e5c5958b59 /Modules/_json.c | |
parent | ee18b6f2fda4afcdd1a22adb5b0637019510907b (diff) | |
download | cpython-136726537ffd92b0f3e8dabb23023ed514852e2e.zip cpython-136726537ffd92b0f3e8dabb23023ed514852e2e.tar.gz cpython-136726537ffd92b0f3e8dabb23023ed514852e2e.tar.bz2 |
#12051: Fix segfault in json.dumps() while encoding highly-nested objects using the C accelerations.
Diffstat (limited to 'Modules/_json.c')
-rw-r--r-- | Modules/_json.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/Modules/_json.c b/Modules/_json.c index 7a995a5..5ced5c9 100644 --- a/Modules/_json.c +++ b/Modules/_json.c @@ -1301,10 +1301,18 @@ encoder_listencode_obj(PyEncoderObject *s, PyObject *rval, PyObject *obj, Py_ssi return _steal_list_append(rval, encoded); } else if (PyList_Check(obj) || PyTuple_Check(obj)) { - return encoder_listencode_list(s, rval, obj, indent_level); + if (Py_EnterRecursiveCall(" while encoding a JSON object")) + return -1; + rv = encoder_listencode_list(s, rval, obj, indent_level); + Py_LeaveRecursiveCall(); + return rv; } else if (PyDict_Check(obj)) { - return encoder_listencode_dict(s, rval, obj, indent_level); + if (Py_EnterRecursiveCall(" while encoding a JSON object")) + return -1; + rv = encoder_listencode_dict(s, rval, obj, indent_level); + Py_LeaveRecursiveCall(); + return rv; } else { PyObject *ident = NULL; @@ -1330,7 +1338,12 @@ encoder_listencode_obj(PyEncoderObject *s, PyObject *rval, PyObject *obj, Py_ssi Py_XDECREF(ident); return -1; } + + if (Py_EnterRecursiveCall(" while encoding a JSON object")) + return -1; rv = encoder_listencode_obj(s, rval, newobj, indent_level); + Py_LeaveRecursiveCall(); + Py_DECREF(newobj); if (rv) { Py_XDECREF(ident); |