Skip to content

Commit 9555348

Browse files
author
Anselm Kruis
committed
Stackless issue python#96: limit the recursion depth of cPickle
Impose a very high recursion limit. Add one call to Py_EnterRecursiveCall() for each stack saving. This stops an infinite recursion after using about 170MB of memory. (grafted from cbc9f897eac548b56ec694a3001130717810e470 and 23ee2a4b0beb)
1 parent 616a6ba commit 9555348

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

Modules/_pickle.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3156,8 +3156,14 @@ save(PicklerObject *self, PyObject *obj, int pers_save)
31563156

31573157
#ifdef STACKLESS
31583158
/* but we save the stack after a fixed watermark */
3159-
if (CSTACK_SAVE_NOW(PyThreadState_GET(), self))
3160-
return slp_safe_pickling((void *)&save, (PyObject *)self, obj, pers_save);
3159+
if (CSTACK_SAVE_NOW(PyThreadState_GET(), self)) {
3160+
int res;
3161+
if (Py_EnterRecursiveCall(" while pickling an object"))
3162+
return -1;
3163+
res = slp_safe_pickling((void *)&save, (PyObject *)self, obj, pers_save);
3164+
Py_LeaveRecursiveCall();
3165+
return res;
3166+
}
31613167
#endif
31623168
if (Py_EnterRecursiveCall(" while pickling an object"))
31633169
return -1;

Stackless/changelog.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
Stackless-Python News
22
+++++++++++++++++++++
33

4-
This file documents changes to the Stackless extension of C-Python.
4+
This file documents user visible changes to the Stackless extension of C-Python.
55
For other changes see Misc/NEWS.
66

7-
87
What's New in Stackless 3.X.X?
98
==============================
109

1110
*Release date: 20XX-XX-XX*
1211

12+
- https://bitbucket.org/stackless-dev/stackless/issues/96
13+
Impose a very high limit on the recursion depth of cPickle.
14+
Previously an infinite recursion could eat up all you memory
15+
and finally crash Stackless. No the recursion stops after using
16+
about 170MB (32bit) / 300MB (64bit) of memory.
17+
1318
- https://bitbucket.org/stackless-dev/stackless/issues/93
1419
Unify tasklet.kill(), tasklet.throw() and tasklet.raise_exception().
1520
They now behave almost identically. This affects the error handling in some

0 commit comments

Comments
 (0)