]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-113595: Don't enter invalid executor (GH-113596)
authorMark Shannon <mark@hotpy.org>
Wed, 3 Jan 2024 11:01:13 +0000 (11:01 +0000)
committerGitHub <noreply@github.com>
Wed, 3 Jan 2024 11:01:13 +0000 (11:01 +0000)
Python/bytecodes.c
Python/generated_cases.c.h

index 29e1dab184ef4e139b6509e971234cb810461b3a..2eeeac53e1dd7e32945013b28ac468749df16307 100644 (file)
@@ -2364,17 +2364,27 @@ dummy_func(
 
             PyCodeObject *code = _PyFrame_GetCode(frame);
             _PyExecutorObject *executor = (_PyExecutorObject *)code->co_executors->executors[oparg&255];
-            Py_INCREF(executor);
-            if (executor->execute == _PyUOpExecute) {
-                current_executor = (_PyUOpExecutorObject *)executor;
-                GOTO_TIER_TWO();
+            if (executor->vm_data.valid) {
+                Py_INCREF(executor);
+                if (executor->execute == _PyUOpExecute) {
+                    current_executor = (_PyUOpExecutorObject *)executor;
+                    GOTO_TIER_TWO();
+                }
+                next_instr = executor->execute(executor, frame, stack_pointer);
+                frame = tstate->current_frame;
+                if (next_instr == NULL) {
+                    goto resume_with_error;
+                }
+                stack_pointer = _PyFrame_GetStackPointer(frame);
             }
-            next_instr = executor->execute(executor, frame, stack_pointer);
-            frame = tstate->current_frame;
-            if (next_instr == NULL) {
-                goto resume_with_error;
+            else {
+                opcode = this_instr->op.code = executor->vm_data.opcode;
+                this_instr->op.arg = executor->vm_data.oparg;
+                oparg = (oparg & (~255)) | executor->vm_data.oparg;
+                code->co_executors->executors[oparg&255] = NULL;
+                Py_DECREF(executor);
+                DISPATCH_GOTO();
             }
-            stack_pointer = _PyFrame_GetStackPointer(frame);
         }
 
         replaced op(_POP_JUMP_IF_FALSE, (cond -- )) {
index ce31967b7912d7341ce7d21bdac81f962c39dba2..99fd169ca4fec3782cc9cd1ac67d9ddca61aab57 100644 (file)
         }
 
         TARGET(ENTER_EXECUTOR) {
-            frame->instr_ptr = next_instr;
+            _Py_CODEUNIT *this_instr = frame->instr_ptr = next_instr;
             next_instr += 1;
             INSTRUCTION_STATS(ENTER_EXECUTOR);
             TIER_ONE_ONLY
             CHECK_EVAL_BREAKER();
             PyCodeObject *code = _PyFrame_GetCode(frame);
             _PyExecutorObject *executor = (_PyExecutorObject *)code->co_executors->executors[oparg&255];
-            Py_INCREF(executor);
-            if (executor->execute == _PyUOpExecute) {
-                current_executor = (_PyUOpExecutorObject *)executor;
-                GOTO_TIER_TWO();
+            if (executor->vm_data.valid) {
+                Py_INCREF(executor);
+                if (executor->execute == _PyUOpExecute) {
+                    current_executor = (_PyUOpExecutorObject *)executor;
+                    GOTO_TIER_TWO();
+                }
+                next_instr = executor->execute(executor, frame, stack_pointer);
+                frame = tstate->current_frame;
+                if (next_instr == NULL) {
+                    goto resume_with_error;
+                }
+                stack_pointer = _PyFrame_GetStackPointer(frame);
             }
-            next_instr = executor->execute(executor, frame, stack_pointer);
-            frame = tstate->current_frame;
-            if (next_instr == NULL) {
-                goto resume_with_error;
+            else {
+                opcode = this_instr->op.code = executor->vm_data.opcode;
+                this_instr->op.arg = executor->vm_data.oparg;
+                oparg = (oparg & (~255)) | executor->vm_data.oparg;
+                code->co_executors->executors[oparg&255] = NULL;
+                Py_DECREF(executor);
+                DISPATCH_GOTO();
             }
-            stack_pointer = _PyFrame_GetStackPointer(frame);
             DISPATCH();
         }