summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2011-05-10 22:02:56 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2011-05-10 22:02:56 (GMT)
commit136726537ffd92b0f3e8dabb23023ed514852e2e (patch)
treec885de5f31a12d00d79c63915e0997e5c5958b59 /Lib
parentee18b6f2fda4afcdd1a22adb5b0637019510907b (diff)
downloadcpython-136726537ffd92b0f3e8dabb23023ed514852e2e.zip
cpython-136726537ffd92b0f3e8dabb23023ed514852e2e.tar.gz
cpython-136726537ffd92b0f3e8dabb23023ed514852e2e.tar.bz2
#12051: Fix segfault in json.dumps() while encoding highly-nested objects using the C accelerations.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/json/tests/test_recursion.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/Lib/json/tests/test_recursion.py b/Lib/json/tests/test_recursion.py
index 6d5db50..ab5f213 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
with self.assertRaises(RuntimeError):
@@ -77,3 +82,17 @@ class TestRecursion(TestCase):
with self.assertRaises(RuntimeError):
json.loads('[' * 100000 + '1' + ']' * 100000)
+ def test_highly_nested_objects_encoding(self):
+ # See #12051
+ l, d = [], {}
+ for x in range(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)