diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2011-05-10 21:55:35 (GMT) |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2011-05-10 21:55:35 (GMT) |
commit | c1ec7b5d441fb6dfdf9499f8fc88a6d891c500be (patch) | |
tree | bd5b7c20366ff95f61de7b0796765ea9fc48a237 /Lib/json/tests/test_recursion.py | |
parent | 47d1d0dc30a81f507fd51cd4c2abfaec735fdf13 (diff) | |
download | cpython-c1ec7b5d441fb6dfdf9499f8fc88a6d891c500be.zip cpython-c1ec7b5d441fb6dfdf9499f8fc88a6d891c500be.tar.gz cpython-c1ec7b5d441fb6dfdf9499f8fc88a6d891c500be.tar.bz2 |
#12051: Fix segfault in json.dumps() while encoding highly-nested objects using the C accelerations.
Diffstat (limited to 'Lib/json/tests/test_recursion.py')
-rw-r--r-- | Lib/json/tests/test_recursion.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/Lib/json/tests/test_recursion.py b/Lib/json/tests/test_recursion.py index 548bb89..1f2d7b3 100644 --- a/Lib/json/tests/test_recursion.py +++ b/Lib/json/tests/test_recursion.py @@ -16,6 +16,11 @@ class RecursiveJSONEncoder(json.JSONEncoder): return 'JSONTestObject' return json.JSONEncoder.default(o) +class EndlessJSONEncoder(json.JSONEncoder): + def default(self, o): + """If check_circular is False, this will keep adding another list.""" + return [o] + class TestRecursion(TestCase): def test_listrecursion(self): @@ -67,7 +72,7 @@ class TestRecursion(TestCase): self.fail("didn't raise ValueError on default recursion") - def test_highly_nested_objects(self): + def test_highly_nested_objects_decoding(self): # test that loading highly-nested objects doesn't segfault when C # accelerations are used. See #12017 # str @@ -84,3 +89,18 @@ class TestRecursion(TestCase): json.loads(u'{"a":' * 100000 + u'[1]' + u'}' * 100000) with self.assertRaises(RuntimeError): json.loads(u'[' * 100000 + u'1' + u']' * 100000) + + def test_highly_nested_objects_encoding(self): + # See #12051 + l, d = [], {} + for x in xrange(100000): + l, d = [l], {'k':d} + with self.assertRaises(RuntimeError): + json.dumps(l) + with self.assertRaises(RuntimeError): + json.dumps(d) + + def test_endless_recursion(self): + # See #12051 + with self.assertRaises(RuntimeError): + EndlessJSONEncoder(check_circular=False).encode(5j) |