diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2020-02-22 13:34:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-22 13:34:06 (GMT) |
commit | 0c1827e70c1c05ce1982a34380cea7d391904293 (patch) | |
tree | e253ef69b53e82c3838142390fcaf054dff0fc8e /Lib/test | |
parent | d6965ff026f35498e554bc964ef2be8f4d80eb7f (diff) | |
download | cpython-0c1827e70c1c05ce1982a34380cea7d391904293.zip cpython-0c1827e70c1c05ce1982a34380cea7d391904293.tar.gz cpython-0c1827e70c1c05ce1982a34380cea7d391904293.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.
(cherry picked from commit 1c56f8ffad44478b4214a2bf8eb7cf51c28a347a)
Co-authored-by: Yonatan Goldschmidt <yon.goldschmidt@gmail.com>
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_isinstance.py | 21 |
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. |