Skip to content

Commit 689e8e7

Browse files
committed
Limit arg_len to co->co_argcount
1 parent 209cd64 commit 689e8e7

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

‎Lib/test/test_capi/test_opt.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,6 +1826,23 @@ def __init__(self, value=sentinel):
18261826
WithDefault()
18271827
"""), PYTHON_JIT="1")
18281828

1829+
def test_init_with_changed_code_argcount(self):
1830+
class C:
1831+
def __init__(self, value):
1832+
self.value = False
1833+
1834+
def varargs_init(self, *args):
1835+
self.value = isinstance(args, tuple)
1836+
1837+
def testfunc(n):
1838+
for _ in range(n):
1839+
result = C(42).value
1840+
return result
1841+
1842+
self.assertFalse(testfunc(100))
1843+
C.__init__.__code__ = C.varargs_init.__code__
1844+
self.assertTrue(testfunc(TIER2_THRESHOLD * 3))
1845+
18291846
def test_init_guards_removed(self):
18301847
class MyPoint:
18311848
def __init__(self, x, y):

‎Python/optimizer_symbols.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,6 +1388,7 @@ _Py_uop_frame_new(
13881388
}
13891389

13901390
// Initialize with the initial state of all local variables
1391+
arg_len = Py_MIN(arg_len, co->co_argcount);
13911392
for (int i = 0; i < arg_len; i++) {
13921393
frame->locals[i] = PyJitRef_RemoveUnique(args[i]);
13931394
}

0 commit comments

Comments
 (0)