Skip to content

Commit 1119ee4

Browse files
authored
[3.11] GH-99298: Don't perform jumps before error handling (GH-99343)
1 parent b31b645 commit 1119ee4

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix an issue that could potentially cause incorrect error handling for some
2+
bytecode instructions.

Python/ceval.c

+11-3
Original file line numberDiff line numberDiff line change
@@ -2158,6 +2158,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
21582158
PyObject *container = SECOND();
21592159
next_instr--;
21602160
if (_Py_Specialize_BinarySubscr(container, sub, next_instr) < 0) {
2161+
next_instr++;
21612162
goto error;
21622163
}
21632164
DISPATCH_SAME_OPARG();
@@ -2323,6 +2324,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
23232324
PyObject *container = SECOND();
23242325
next_instr--;
23252326
if (_Py_Specialize_StoreSubscr(container, sub, next_instr) < 0) {
2327+
next_instr++;
23262328
goto error;
23272329
}
23282330
DISPATCH_SAME_OPARG();
@@ -3056,6 +3058,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
30563058
PyObject *name = GETITEM(names, oparg>>1);
30573059
next_instr--;
30583060
if (_Py_Specialize_LoadGlobal(GLOBALS(), BUILTINS(), next_instr, name) < 0) {
3061+
next_instr++;
30593062
goto error;
30603063
}
30613064
DISPATCH_SAME_OPARG();
@@ -3481,6 +3484,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
34813484
PyObject *name = GETITEM(names, oparg);
34823485
next_instr--;
34833486
if (_Py_Specialize_LoadAttr(owner, next_instr, name) < 0) {
3487+
next_instr++;
34843488
goto error;
34853489
}
34863490
DISPATCH_SAME_OPARG();
@@ -3590,6 +3594,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
35903594
PyObject *name = GETITEM(names, oparg);
35913595
next_instr--;
35923596
if (_Py_Specialize_StoreAttr(owner, next_instr, name) < 0) {
3597+
next_instr++;
35933598
goto error;
35943599
}
35953600
DISPATCH_SAME_OPARG();
@@ -4527,6 +4532,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
45274532
PyObject *name = GETITEM(names, oparg);
45284533
next_instr--;
45294534
if (_Py_Specialize_LoadMethod(owner, next_instr, name) < 0) {
4535+
next_instr++;
45304536
goto error;
45314537
}
45324538
DISPATCH_SAME_OPARG();
@@ -4801,6 +4807,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
48014807
int err = _Py_Specialize_Precall(callable, next_instr, nargs,
48024808
call_shape.kwnames, oparg);
48034809
if (err < 0) {
4810+
next_instr++;
48044811
goto error;
48054812
}
48064813
DISPATCH_SAME_OPARG();
@@ -4822,6 +4829,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
48224829
int err = _Py_Specialize_Call(callable, next_instr, nargs,
48234830
call_shape.kwnames);
48244831
if (err < 0) {
4832+
next_instr++;
48254833
goto error;
48264834
}
48274835
DISPATCH_SAME_OPARG();
@@ -5184,16 +5192,16 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
51845192
PyObject *list = SECOND();
51855193
DEOPT_IF(!PyList_Check(list), PRECALL);
51865194
STAT_INC(PRECALL, hit);
5187-
// PRECALL + CALL + POP_TOP
5188-
JUMPBY(INLINE_CACHE_ENTRIES_PRECALL + 1 + INLINE_CACHE_ENTRIES_CALL + 1);
5189-
assert(_Py_OPCODE(next_instr[-1]) == POP_TOP);
51905195
PyObject *arg = POP();
51915196
if (_PyList_AppendTakeRef((PyListObject *)list, arg) < 0) {
51925197
goto error;
51935198
}
51945199
STACK_SHRINK(2);
51955200
Py_DECREF(list);
51965201
Py_DECREF(callable);
5202+
// PRECALL + CALL + POP_TOP
5203+
JUMPBY(INLINE_CACHE_ENTRIES_PRECALL + 1 + INLINE_CACHE_ENTRIES_CALL + 1);
5204+
assert(_Py_OPCODE(next_instr[-1]) == POP_TOP);
51975205
DISPATCH();
51985206
}
51995207

0 commit comments

Comments
 (0)