From 5a30620e68ebb911eef4d583de3776d782148637 Mon Sep 17 00:00:00 2001 From: jdemeyer Date: Fri, 19 Oct 2018 23:50:06 +0200 Subject: bpo-25750: Add test on bad descriptor __get__() (GH-9084) --- Lib/test/test_descr.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'Lib/test/test_descr.py') diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index b96d35cc72..b38cb765cd 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -13,6 +13,11 @@ import weakref from copy import deepcopy from test import support +try: + import _testcapi +except ImportError: + _testcapi = None + class OperatorsTest(unittest.TestCase): @@ -4757,6 +4762,22 @@ order (MRO) for bases """ self.assertRegex(repr(method), r">") + @unittest.skipIf(_testcapi is None, 'need the _testcapi module') + def test_bpo25750(self): + # bpo-25750: calling a descriptor (implemented as built-in + # function with METH_FASTCALL) should not crash CPython if the + # descriptor deletes itself from the class. + class Descr: + __get__ = _testcapi.bad_get + + class X: + descr = Descr() + def __new__(cls): + cls.descr = None + # Create this large list to corrupt some unused memory + cls.lst = [2**i for i in range(10000)] + X.descr + class DictProxyTests(unittest.TestCase): def setUp(self): -- cgit v1.2.1