[3.13] gh-134163: Fix an infinite loop when the process runs out of memory in a try block (GH-138491)

Signed-off-by: yihong0618 <zouzou0208@gmail.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
This commit is contained in:
yihong 2025-09-11 00:54:42 +08:00 committed by GitHub
parent 443d4af2ee
commit afec6a5460
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 38 additions and 1 deletions

View file

@ -912,7 +912,11 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
int frame_lasti = _PyInterpreterFrame_LASTI(frame);
PyObject *lasti = PyLong_FromLong(frame_lasti);
if (lasti == NULL) {
goto exception_unwind;
// Instead of going back to exception_unwind (which would cause
// infinite recursion), directly exit to let the original exception
// propagate up and hopefully be handled at a higher level.
_PyFrame_SetStackPointer(frame, stack_pointer);
goto exit_unwind;
}
PUSH(lasti);
}