bpo-30570: Fix segfault on buildbots caused by stack overflow from recursion in tests (GH-29258)

* Don't stackoveflow on debug builds

* Also catch the pickletester case
This commit is contained in:
Dennis Sweeney 2021-10-28 06:11:18 -04:00 committed by GitHub
parent 4c95fb4640
commit d56375a0dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 12 deletions

View File

@ -2383,7 +2383,8 @@ class AbstractPickleTests:
# Issue #3514: crash when there is an infinite loop in __getattr__
x = BadGetattr()
for proto in protocols:
self.assertRaises(RuntimeError, self.dumps, x, proto)
with support.infinite_recursion():
self.assertRaises(RuntimeError, self.dumps, x, proto)
def test_reduce_bad_iterator(self):
# Issue4176: crash when 4th and 5th items of __reduce__()

View File

@ -5,6 +5,7 @@
import unittest
import sys
import typing
from test import support
@ -266,12 +267,14 @@ class TestIsInstanceIsSubclass(unittest.TestCase):
def test_subclass_recursion_limit(self):
# make sure that issubclass raises RecursionError before the C stack is
# blown
self.assertRaises(RecursionError, blowstack, issubclass, str, str)
with support.infinite_recursion():
self.assertRaises(RecursionError, blowstack, issubclass, str, str)
def test_isinstance_recursion_limit(self):
# make sure that issubclass raises RecursionError before the C stack is
# blown
self.assertRaises(RecursionError, blowstack, isinstance, '', str)
with support.infinite_recursion():
self.assertRaises(RecursionError, blowstack, isinstance, '', str)
def test_subclass_with_union(self):
self.assertTrue(issubclass(int, int | float | int))
@ -308,19 +311,19 @@ class TestIsInstanceIsSubclass(unittest.TestCase):
@property
def __bases__(self):
return self.__bases__
self.assertRaises(RecursionError, issubclass, X(), int)
self.assertRaises(RecursionError, issubclass, int, X())
self.assertRaises(RecursionError, isinstance, 1, X())
with support.infinite_recursion():
self.assertRaises(RecursionError, issubclass, X(), int)
self.assertRaises(RecursionError, issubclass, int, X())
self.assertRaises(RecursionError, isinstance, 1, X())
def test_infinite_recursion_via_bases_tuple(self):
"""Regression test for bpo-30570."""
class Failure(object):
def __getattr__(self, attr):
return (self, None)
with self.assertRaises(RecursionError):
issubclass(Failure(), int)
with support.infinite_recursion():
with self.assertRaises(RecursionError):
issubclass(Failure(), int)
def test_infinite_cycle_in_bases(self):
"""Regression test for bpo-30570."""
@ -328,7 +331,8 @@ class TestIsInstanceIsSubclass(unittest.TestCase):
@property
def __bases__(self):
return (self, self, self)
self.assertRaises(RecursionError, issubclass, X(), int)
with support.infinite_recursion():
self.assertRaises(RecursionError, issubclass, X(), int)
def test_infinitely_many_bases(self):
"""Regression test for bpo-30570."""
@ -341,7 +345,8 @@ class TestIsInstanceIsSubclass(unittest.TestCase):
pass
A.__getattr__ = B.__getattr__ = X.__getattr__
return (A(), B())
self.assertRaises(RecursionError, issubclass, X(), int)
with support.infinite_recursion():
self.assertRaises(RecursionError, issubclass, X(), int)
def blowstack(fxn, arg, compare_to):