summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2007-05-18 05:47:16 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2007-05-18 05:47:16 (GMT)
commit6eb7bede72f044b0b6a73551c04281defc7fc489 (patch)
tree812956114bfef77b8c4d6ae91f489550b2c2210c /Lib
parent88d96ade596bbf5bd4c0f737569b5315568ccd7b (diff)
downloadcpython-6eb7bede72f044b0b6a73551c04281defc7fc489.zip
cpython-6eb7bede72f044b0b6a73551c04281defc7fc489.tar.gz
cpython-6eb7bede72f044b0b6a73551c04281defc7fc489.tar.bz2
Verify neither dumps or loads overflow the stack and segfault.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_marshal.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/Lib/test/test_marshal.py b/Lib/test/test_marshal.py
index bfdd274..656fc1f 100644
--- a/Lib/test/test_marshal.py
+++ b/Lib/test/test_marshal.py
@@ -220,10 +220,30 @@ class BugsTestCase(unittest.TestCase):
except Exception:
pass
- def test_recursion(self):
+ def test_loads_recursion(self):
s = 'c' + ('X' * 4*4) + '{' * 2**20
self.assertRaises(ValueError, marshal.loads, s)
+ def test_recursion_limit(self):
+ # Create a deeply nested structure.
+ head = last = []
+ # The max stack depth should match the value in Python/marshal.c.
+ MAX_MARSHAL_STACK_DEPTH = 2000
+ for i in range(MAX_MARSHAL_STACK_DEPTH - 2):
+ last.append([0])
+ last = last[-1]
+
+ # Verify we don't blow out the stack with dumps/load.
+ data = marshal.dumps(head)
+ new_head = marshal.loads(data)
+ # Don't use == to compare objects, it can exceed the recursion limit.
+ self.assertEqual(len(new_head), len(head))
+ self.assertEqual(len(new_head[0]), len(head[0]))
+ self.assertEqual(len(new_head[-1]), len(head[-1]))
+
+ last.append([0])
+ self.assertRaises(ValueError, marshal.dumps, head)
+
def test_main():
test_support.run_unittest(IntTestCase,
FloatTestCase,