Skip to content

Commit dc62b62

Browse files
GH-141861: Fix invalid memory read in the ENTER_EXECUTOR (GH-141921)
1 parent 369ce2b commit dc62b62

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2662,6 +2662,38 @@ def f():
26622662
f" {executor} at offset {idx} rather"
26632663
f" than expected _EXIT_TRACE")
26642664

2665+
def test_enter_executor_valid_op_arg(self):
2666+
script_helper.assert_python_ok("-c", textwrap.dedent("""
2667+
import sys
2668+
sys.setrecursionlimit(30) # reduce time of the run
2669+
2670+
str_v1 = ''
2671+
tuple_v2 = (None, None, None, None, None)
2672+
small_int_v3 = 4
2673+
2674+
def f1():
2675+
2676+
for _ in range(10):
2677+
abs(0)
2678+
2679+
tuple_v2[small_int_v3]
2680+
tuple_v2[small_int_v3]
2681+
tuple_v2[small_int_v3]
2682+
2683+
def recursive_wrapper_4569():
2684+
str_v1 > str_v1
2685+
str_v1 > str_v1
2686+
str_v1 > str_v1
2687+
recursive_wrapper_4569()
2688+
2689+
recursive_wrapper_4569()
2690+
2691+
for i_f1 in range(19000):
2692+
try:
2693+
f1()
2694+
except RecursionError:
2695+
pass
2696+
"""))
26652697

26662698

26672699
def global_identity(x):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix invalid memory read in the ``ENTER_EXECUTOR`` instruction.

Python/bytecodes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3018,7 +3018,7 @@ dummy_func(
30183018
goto stop_tracing;
30193019
}
30203020
PyCodeObject *code = _PyFrame_GetCode(frame);
3021-
_PyExecutorObject *executor = code->co_executors->executors[oparg & 255];
3021+
_PyExecutorObject *executor = code->co_executors->executors[this_instr->op.arg];
30223022
assert(executor->vm_data.index == INSTR_OFFSET() - 1);
30233023
assert(executor->vm_data.code == code);
30243024
assert(executor->vm_data.valid);

Python/generated_cases.c.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)