modre: Report if regex is too complex.

If the error reporting mode is at least "normal", report a failure
due to a complex regex with a different message.

Closes: #17150
Signed-off-by: Jeff Epler <jepler@gmail.com>
This commit is contained in:
Jeff Epler 2025-06-01 18:47:36 +02:00
parent f5d10c322e
commit ee31febb0b

View file

@ -427,6 +427,9 @@ static mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args) {
const char *re_str = mp_obj_str_get_str(args[0]);
int size = re1_5_sizecode(re_str);
if (size == -1) {
#if MICROPY_ERROR_REPORTING >= MICROPY_ERROR_REPORTING_NORMAL
mp_raise_ValueError(MP_ERROR_TEXT("regex too complex"));
#endif
goto error;
}
mp_obj_re_t *o = mp_obj_malloc_var(mp_obj_re_t, re.insts, char, size, (mp_obj_type_t *)&re_type);