diff options
author | Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com> | 2021-10-28 10:11:18 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-28 10:11:18 (GMT) |
commit | d56375a0dd4cee162081b173310298a3d32af293 (patch) | |
tree | 5d9ecb5cff63e670aa40e4c0f1cbe655dc7dedad | |
parent | 4c95fb4640c0247903562dae4478158b348cea6d (diff) | |
download | cpython-d56375a0dd4cee162081b173310298a3d32af293.zip cpython-d56375a0dd4cee162081b173310298a3d32af293.tar.gz cpython-d56375a0dd4cee162081b173310298a3d32af293.tar.bz2 |
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
-rw-r--r-- | Lib/test/pickletester.py | 3 | ||||
-rw-r--r-- | Lib/test/test_isinstance.py | 27 |
2 files changed, 18 insertions, 12 deletions
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index 3e2c781..f13d42f 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -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__() diff --git a/Lib/test/test_isinstance.py b/Lib/test/test_isinstance.py index 6ab44be..9d37cff 100644 --- a/Lib/test/test_isinstance.py +++ b/Lib/test/test_isinstance.py @@ -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): |