mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
[3.12] gh-107450: Raise OverflowError when parser column offset overflows (GH-110754) (#110762)
(cherry picked from commit fb7843ee89
)
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
This commit is contained in:
parent
e8d04190c6
commit
ea3ac56a05
2 changed files with 10 additions and 0 deletions
|
@ -318,6 +318,10 @@ class ExceptionTests(unittest.TestCase):
|
||||||
check('(yield i) = 2', 1, 2)
|
check('(yield i) = 2', 1, 2)
|
||||||
check('def f(*):\n pass', 1, 7)
|
check('def f(*):\n pass', 1, 7)
|
||||||
|
|
||||||
|
def testMemoryErrorBigSource(self):
|
||||||
|
with self.assertRaisesRegex(OverflowError, "column offset overflow"):
|
||||||
|
exec(f"if True:\n {' ' * 2**31}print('hello world')")
|
||||||
|
|
||||||
@cpython_only
|
@cpython_only
|
||||||
def testSettingException(self):
|
def testSettingException(self):
|
||||||
# test that setting an exception at the C level works even if the
|
# test that setting an exception at the C level works even if the
|
||||||
|
|
|
@ -233,6 +233,12 @@ _PyPegen_raise_error(Parser *p, PyObject *errtype, int use_mark, const char *err
|
||||||
col_offset = 0;
|
col_offset = 0;
|
||||||
} else {
|
} else {
|
||||||
const char* start = p->tok->buf ? p->tok->line_start : p->tok->buf;
|
const char* start = p->tok->buf ? p->tok->line_start : p->tok->buf;
|
||||||
|
if (p->tok->cur - start > INT_MAX) {
|
||||||
|
PyErr_SetString(PyExc_OverflowError,
|
||||||
|
"Parser column offset overflow - source line is too big");
|
||||||
|
p->error_indicator = 1;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
col_offset = Py_SAFE_DOWNCAST(p->tok->cur - start, intptr_t, int);
|
col_offset = Py_SAFE_DOWNCAST(p->tok->cur - start, intptr_t, int);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue