Skip to content

[3.11] GH-99298: Don't perform jumps before error handling #99343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix an issue that could potentially cause incorrect error handling for some
bytecode instructions.
14 changes: 11 additions & 3 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -2158,6 +2158,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
PyObject *container = SECOND();
next_instr--;
if (_Py_Specialize_BinarySubscr(container, sub, next_instr) < 0) {
next_instr++;
goto error;
}
DISPATCH_SAME_OPARG();
Expand Down Expand Up @@ -2323,6 +2324,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
PyObject *container = SECOND();
next_instr--;
if (_Py_Specialize_StoreSubscr(container, sub, next_instr) < 0) {
next_instr++;
goto error;
}
DISPATCH_SAME_OPARG();
Expand Down Expand Up @@ -3056,6 +3058,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
PyObject *name = GETITEM(names, oparg>>1);
next_instr--;
if (_Py_Specialize_LoadGlobal(GLOBALS(), BUILTINS(), next_instr, name) < 0) {
next_instr++;
goto error;
}
DISPATCH_SAME_OPARG();
Expand Down Expand Up @@ -3481,6 +3484,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
PyObject *name = GETITEM(names, oparg);
next_instr--;
if (_Py_Specialize_LoadAttr(owner, next_instr, name) < 0) {
next_instr++;
goto error;
}
DISPATCH_SAME_OPARG();
Expand Down Expand Up @@ -3590,6 +3594,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
PyObject *name = GETITEM(names, oparg);
next_instr--;
if (_Py_Specialize_StoreAttr(owner, next_instr, name) < 0) {
next_instr++;
goto error;
}
DISPATCH_SAME_OPARG();
Expand Down Expand Up @@ -4527,6 +4532,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
PyObject *name = GETITEM(names, oparg);
next_instr--;
if (_Py_Specialize_LoadMethod(owner, next_instr, name) < 0) {
next_instr++;
goto error;
}
DISPATCH_SAME_OPARG();
Expand Down Expand Up @@ -4801,6 +4807,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
int err = _Py_Specialize_Precall(callable, next_instr, nargs,
call_shape.kwnames, oparg);
if (err < 0) {
next_instr++;
goto error;
}
DISPATCH_SAME_OPARG();
Expand All @@ -4822,6 +4829,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
int err = _Py_Specialize_Call(callable, next_instr, nargs,
call_shape.kwnames);
if (err < 0) {
next_instr++;
goto error;
}
DISPATCH_SAME_OPARG();
Expand Down Expand Up @@ -5184,16 +5192,16 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
PyObject *list = SECOND();
DEOPT_IF(!PyList_Check(list), PRECALL);
STAT_INC(PRECALL, hit);
// PRECALL + CALL + POP_TOP
JUMPBY(INLINE_CACHE_ENTRIES_PRECALL + 1 + INLINE_CACHE_ENTRIES_CALL + 1);
assert(_Py_OPCODE(next_instr[-1]) == POP_TOP);
PyObject *arg = POP();
if (_PyList_AppendTakeRef((PyListObject *)list, arg) < 0) {
goto error;
}
STACK_SHRINK(2);
Py_DECREF(list);
Py_DECREF(callable);
// PRECALL + CALL + POP_TOP
JUMPBY(INLINE_CACHE_ENTRIES_PRECALL + 1 + INLINE_CACHE_ENTRIES_CALL + 1);
assert(_Py_OPCODE(next_instr[-1]) == POP_TOP);
DISPATCH();
}

Expand Down