Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0f2a61a

Browse files
committed
Merged revisions 88147 via svnmerge from
svn+ssh://[email protected]/python/branches/py3k ........ r88147 | antoine.pitrou | 2011-01-23 18:12:25 +0100 (dim., 23 janv. 2011) | 3 lines Issue #10987: Fix the recursion limit handling in the _pickle module. ........
1 parent eb9d5ad commit 0f2a61a

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Core and Builtins
3737
Library
3838
-------
3939

40+
- Issue #10987: Fix the recursion limit handling in the _pickle module.
41+
4042
- Issue #10949: Improved robustness of rotating file handlers.
4143

4244
- Issue #10955: Fix a potential crash when trying to mmap() a file past its

Modules/_pickle.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,7 +1566,12 @@ save_list(PicklerObject *self, PyObject *obj)
15661566
iter = PyObject_GetIter(obj);
15671567
if (iter == NULL)
15681568
goto error;
1569+
if (Py_EnterRecursiveCall(" while pickling an object")) {
1570+
Py_DECREF(iter);
1571+
goto error;
1572+
}
15691573
status = batch_list(self, iter);
1574+
Py_LeaveRecursiveCall();
15701575
Py_DECREF(iter);
15711576
}
15721577

@@ -1814,10 +1819,10 @@ save_dict(PicklerObject *self, PyObject *obj)
18141819
if (PyDict_CheckExact(obj) && self->proto > 0) {
18151820
/* We can take certain shortcuts if we know this is a dict and
18161821
not a dict subclass. */
1817-
if (Py_EnterRecursiveCall(" while pickling an object") == 0) {
1818-
status = batch_dict_exact(self, obj);
1819-
Py_LeaveRecursiveCall();
1820-
}
1822+
if (Py_EnterRecursiveCall(" while pickling an object"))
1823+
goto error;
1824+
status = batch_dict_exact(self, obj);
1825+
Py_LeaveRecursiveCall();
18211826
} else {
18221827
items = PyObject_CallMethod(obj, "items", "()");
18231828
if (items == NULL)
@@ -1826,7 +1831,12 @@ save_dict(PicklerObject *self, PyObject *obj)
18261831
Py_DECREF(items);
18271832
if (iter == NULL)
18281833
goto error;
1834+
if (Py_EnterRecursiveCall(" while pickling an object")) {
1835+
Py_DECREF(iter);
1836+
goto error;
1837+
}
18291838
status = batch_dict(self, iter);
1839+
Py_LeaveRecursiveCall();
18301840
Py_DECREF(iter);
18311841
}
18321842
}
@@ -2353,7 +2363,7 @@ save(PicklerObject *self, PyObject *obj, int pers_save)
23532363
PyObject *memo_key = NULL;
23542364
int status = 0;
23552365

2356-
if (Py_EnterRecursiveCall(" while pickling an object") < 0)
2366+
if (Py_EnterRecursiveCall(" while pickling an object"))
23572367
return -1;
23582368

23592369
/* The extra pers_save argument is necessary to avoid calling save_pers()

Tools/scripts/find_recursionlimit.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,15 @@ def test_cpickle(_cache={}):
7777
except ImportError:
7878
print("cannot import _pickle, skipped!")
7979
return
80-
l = None
80+
k, l = None, None
8181
for n in itertools.count():
8282
try:
8383
l = _cache[n]
8484
continue # Already tried and it works, let's save some time
8585
except KeyError:
8686
for i in range(100):
87-
l = [l]
87+
l = [k, l]
88+
k = {i: l}
8889
_pickle.Pickler(io.BytesIO(), protocol=-1).dump(l)
8990
_cache[n] = l
9091

0 commit comments

Comments
 (0)