summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorYonatan Goldschmidt <yon.goldschmidt@gmail.com>2020-02-22 13:11:48 (GMT)
committerGitHub <noreply@github.com>2020-02-22 13:11:48 (GMT)
commit1c56f8ffad44478b4214a2bf8eb7cf51c28a347a (patch)
treec2303c03737343e14f7720a97200bb007845ac7b /Lib
parenta025d4ca99fb4c652465368e0b4eb03cf4b316b9 (diff)
downloadcpython-1c56f8ffad44478b4214a2bf8eb7cf51c28a347a.zip
cpython-1c56f8ffad44478b4214a2bf8eb7cf51c28a347a.tar.gz
cpython-1c56f8ffad44478b4214a2bf8eb7cf51c28a347a.tar.bz2
bpo-39382: Avoid dangling object use in abstract_issubclass() (GH-18530)
Hold reference of __bases__ tuple until tuple item is done with, because by dropping the reference the item may be destroyed.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_isinstance.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_isinstance.py b/Lib/test/test_isinstance.py
index 65751ab..53639e9 100644
--- a/Lib/test/test_isinstance.py
+++ b/Lib/test/test_isinstance.py
@@ -251,6 +251,27 @@ class TestIsInstanceIsSubclass(unittest.TestCase):
# blown
self.assertRaises(RecursionError, blowstack, isinstance, '', str)
+ def test_issubclass_refcount_handling(self):
+ # bpo-39382: abstract_issubclass() didn't hold item reference while
+ # peeking in the bases tuple, in the single inheritance case.
+ class A:
+ @property
+ def __bases__(self):
+ return (int, )
+
+ class B:
+ def __init__(self):
+ # setting this here increases the chances of exhibiting the bug,
+ # probably due to memory layout changes.
+ self.x = 1
+
+ @property
+ def __bases__(self):
+ return (A(), )
+
+ self.assertEqual(True, issubclass(B(), int))
+
+
def blowstack(fxn, arg, compare_to):
# Make sure that calling isinstance with a deeply nested tuple for its
# argument will raise RecursionError eventually.