#3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.

Reviewed by Martin von Loewis.
This commit is contained in:
Amaury Forgeot d'Arc 2008-09-11 20:56:13 +00:00
parent d2e0938362
commit 24cb382455
3 changed files with 142 additions and 67 deletions

View file

@ -22,6 +22,7 @@ NB: A program that does not use __methods__ can set a higher limit.
"""
import sys
import itertools
class RecursiveBlowup1:
def __init__(self):
@ -61,6 +62,23 @@ def test_getitem():
def test_recurse():
return test_recurse()
def test_cpickle(_cache={}):
try:
import cPickle
except ImportError:
print "cannot import cPickle, skipped!"
return
l = None
for n in itertools.count():
try:
l = _cache[n]
continue # Already tried and it works, let's save some time
except KeyError:
for i in range(100):
l = [l]
cPickle.dumps(l, protocol=-1)
_cache[n] = l
def check_limit(n, test_func_name):
sys.setrecursionlimit(n)
if test_func_name.startswith("test_"):
@ -83,5 +101,6 @@ while 1:
check_limit(limit, "test_init")
check_limit(limit, "test_getattr")
check_limit(limit, "test_getitem")
check_limit(limit, "test_cpickle")
print "Limit of %d is fine" % limit
limit = limit + 100