diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-11-01 18:52:06 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-11-01 18:52:06 (GMT) |
commit | 9f69e79c450c3c17172046f937941e6df1802a6d (patch) | |
tree | 346e98946bad3a96f6a939ab6dfb2c53b81e00b2 /Modules/_json.c | |
parent | 42d5c415224cf0bae36c74840b0d1c481f3ee99b (diff) | |
download | cpython-9f69e79c450c3c17172046f937941e6df1802a6d.zip cpython-9f69e79c450c3c17172046f937941e6df1802a6d.tar.gz cpython-9f69e79c450c3c17172046f937941e6df1802a6d.tar.bz2 |
Issue #16228: Fix a crash in the json module where a list changes size while it is being encoded.
Patch by Serhiy Storchaka.
Diffstat (limited to 'Modules/_json.c')
-rw-r--r-- | Modules/_json.c | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/Modules/_json.c b/Modules/_json.c index 2a71b9f..01436b6 100644 --- a/Modules/_json.c +++ b/Modules/_json.c @@ -1585,8 +1585,6 @@ encoder_listencode_list(PyEncoderObject *s, PyObject *rval, PyObject *seq, Py_ss static PyObject *empty_array = NULL; PyObject *ident = NULL; PyObject *s_fast = NULL; - Py_ssize_t num_items; - PyObject **seq_items; Py_ssize_t i; if (open_array == NULL || close_array == NULL || empty_array == NULL) { @@ -1600,8 +1598,7 @@ encoder_listencode_list(PyEncoderObject *s, PyObject *rval, PyObject *seq, Py_ss s_fast = PySequence_Fast(seq, "_iterencode_list needs a sequence"); if (s_fast == NULL) return -1; - num_items = PySequence_Fast_GET_SIZE(s_fast); - if (num_items == 0) { + if (PySequence_Fast_GET_SIZE(s_fast) == 0) { Py_DECREF(s_fast); return PyList_Append(rval, empty_array); } @@ -1622,7 +1619,6 @@ encoder_listencode_list(PyEncoderObject *s, PyObject *rval, PyObject *seq, Py_ss } } - seq_items = PySequence_Fast_ITEMS(s_fast); if (PyList_Append(rval, open_array)) goto bail; if (s->indent != Py_None) { @@ -1634,8 +1630,8 @@ encoder_listencode_list(PyEncoderObject *s, PyObject *rval, PyObject *seq, Py_ss buf += newline_indent */ } - for (i = 0; i < num_items; i++) { - PyObject *obj = seq_items[i]; + for (i = 0; i < PySequence_Fast_GET_SIZE(s_fast); i++) { + PyObject *obj = PySequence_Fast_GET_ITEM(s_fast, i); if (i) { if (PyList_Append(rval, s->item_separator)) goto bail; |