mirror of https://github.com/python/cpython
gh-108179: Add error message for parser stack overflows (#108256)
This commit is contained in:
parent
7f87ebbc3f
commit
86617518c4
|
@ -2335,7 +2335,7 @@ while 1:
|
|||
source = "-" * 100000 + "4"
|
||||
for mode in ["exec", "eval", "single"]:
|
||||
with self.subTest(mode=mode):
|
||||
with self.assertRaises(MemoryError):
|
||||
with self.assertRaisesRegex(MemoryError, r"too complex"):
|
||||
compile(source, "<string>", mode)
|
||||
|
||||
@support.cpython_only
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -166,6 +166,8 @@ void *_PyPegen_raise_error_known_location(Parser *p, PyObject *errtype,
|
|||
Py_ssize_t end_lineno, Py_ssize_t end_col_offset,
|
||||
const char *errmsg, va_list va);
|
||||
void _Pypegen_set_syntax_error(Parser* p, Token* last_token);
|
||||
void _Pypegen_stack_overflow(Parser *p);
|
||||
|
||||
Py_LOCAL_INLINE(void *)
|
||||
RAISE_ERROR_KNOWN_LOCATION(Parser *p, PyObject *errtype,
|
||||
Py_ssize_t lineno, Py_ssize_t col_offset,
|
||||
|
|
|
@ -454,3 +454,11 @@ _Pypegen_set_syntax_error(Parser* p, Token* last_token) {
|
|||
// generic SyntaxError we just raised if errors are found.
|
||||
_PyPegen_tokenize_full_source_to_check_for_errors(p);
|
||||
}
|
||||
|
||||
void
|
||||
_Pypegen_stack_overflow(Parser *p)
|
||||
{
|
||||
p->error_indicator = 1;
|
||||
PyErr_SetString(PyExc_MemoryError,
|
||||
"Parser stack overflowed - Python source too complex to parse");
|
||||
}
|
||||
|
|
|
@ -375,8 +375,7 @@ class CParserGenerator(ParserGenerator, GrammarVisitor):
|
|||
def add_level(self) -> None:
|
||||
self.print("if (p->level++ == MAXSTACK) {")
|
||||
with self.indent():
|
||||
self.print("p->error_indicator = 1;")
|
||||
self.print("PyErr_NoMemory();")
|
||||
self.print("_Pypegen_stack_overflow(p);")
|
||||
self.print("}")
|
||||
|
||||
def remove_level(self) -> None:
|
||||
|
|
Loading…
Reference in New Issue