diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2020-10-04 22:28:00 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-04 22:28:00 (GMT) |
commit | 09a7b3b618cd02694a0bc8abfa24c75f0e659407 (patch) | |
tree | fe81737f24de56c6cd798f261dc73df39e81aa85 /Lib/test/test_isinstance.py | |
parent | 28cd96f2e5cfb16566a75dca8473b71889746f10 (diff) | |
download | cpython-09a7b3b618cd02694a0bc8abfa24c75f0e659407.zip cpython-09a7b3b618cd02694a0bc8abfa24c75f0e659407.tar.gz cpython-09a7b3b618cd02694a0bc8abfa24c75f0e659407.tar.bz2 |
[3.8] bpo-41909: Enable previously disabled recursion checks. (GH-22536) (GH-22551)
Enable recursion checks which were disabled when get __bases__ of
non-type objects in issubclass() and isinstance() and when intern
strings. It fixes a stack overflow when getting __bases__ leads
to infinite recursion.
Originally recursion checks was disabled for PyDict_GetItem() which
silences all errors including the one raised in case of detected
recursion and can return incorrect result. But now the code uses
PyDict_GetItemWithError() and PyDict_SetDefault() instead.
(cherry picked from commit 9ece9cd65cdeb0a1f6e60475bbd0219161c348ac)
Diffstat (limited to 'Lib/test/test_isinstance.py')
-rw-r--r-- | Lib/test/test_isinstance.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/test_isinstance.py b/Lib/test/test_isinstance.py index 53639e9..31b3899 100644 --- a/Lib/test/test_isinstance.py +++ b/Lib/test/test_isinstance.py @@ -271,6 +271,16 @@ class TestIsInstanceIsSubclass(unittest.TestCase): self.assertEqual(True, issubclass(B(), int)) + def test_infinite_recursion_in_bases(self): + class X: + @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()) + def blowstack(fxn, arg, compare_to): # Make sure that calling isinstance with a deeply nested tuple for its |