diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-12-03 20:12:11 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-03 20:12:11 (GMT) |
commit | 1fb72d2ad243c965d4432b4e93884064001a2607 (patch) | |
tree | 00296a976e5e386a94c0bb6f8ed535b1c30621f5 /Objects | |
parent | eea3cc1ef0dec0af193eedb4c1164263fbdfd8cc (diff) | |
download | cpython-1fb72d2ad243c965d4432b4e93884064001a2607.zip cpython-1fb72d2ad243c965d4432b4e93884064001a2607.tar.gz cpython-1fb72d2ad243c965d4432b4e93884064001a2607.tar.bz2 |
bpo-32137: The repr of deeply nested dict now raises a RecursionError (#4570)
instead of crashing due to a stack overflow.
This perhaps will fix similar problems in other extension types.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/listobject.c | 3 | ||||
-rw-r--r-- | Objects/object.c | 5 | ||||
-rw-r--r-- | Objects/tupleobject.c | 3 |
3 files changed, 5 insertions, 6 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c index 8576b7a..8794e37 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -364,10 +364,7 @@ list_repr(PyListObject *v) goto error; } - if (Py_EnterRecursiveCall(" while getting the repr of a list")) - goto error; s = PyObject_Repr(v->ob_item[i]); - Py_LeaveRecursiveCall(); if (s == NULL) goto error; diff --git a/Objects/object.c b/Objects/object.c index 674180d..a0d651d 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -463,7 +463,12 @@ PyObject_Repr(PyObject *v) assert(!PyErr_Occurred()); #endif + /* It is possible for a type to have a tp_repr representation that loops + infinitely. */ + if (Py_EnterRecursiveCall(" while getting the repr of an object")) + return NULL; res = (*v->ob_type->tp_repr)(v); + Py_LeaveRecursiveCall(); if (res == NULL) return NULL; if (!PyUnicode_Check(res)) { diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index 964db3b..3a60946 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -303,10 +303,7 @@ tuplerepr(PyTupleObject *v) goto error; } - if (Py_EnterRecursiveCall(" while getting the repr of a tuple")) - goto error; s = PyObject_Repr(v->ob_item[i]); - Py_LeaveRecursiveCall(); if (s == NULL) goto error; |