Skip to content

Commit f459c4b

Browse files
committed
gh-151763: Restore exception if parser recovery path leaves none set
After the diagnostic second parse pass, call PyErr_NoMemory() when no exception is set so callers do not hit _Py_CheckFunctionResult fatals (OOM-0021).
1 parent f5f5059 commit f459c4b

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a crash in the parser recovery path when an allocation failure leaves no
2+
exception set.

Parser/pegen.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,12 @@ _PyPegen_run_parser(Parser *p)
10261026
if (PyErr_ExceptionMatches(PyExc_SyntaxError)) {
10271027
_PyPegen_set_syntax_error_metadata(p);
10281028
}
1029-
return NULL;
1029+
if (!PyErr_Occurred()) {
1030+
/* Under OOM the recovery pass can clear the exception and fail
1031+
silently; restore the result/error contract. */
1032+
PyErr_NoMemory();
1033+
}
1034+
return NULL;
10301035
}
10311036

10321037
if (p->start_rule == Py_single_input && bad_single_statement(p)) {

0 commit comments

Comments
 (0)