Skip to content

Commit 745bec9

Browse files
jeplerdpgeorge
authored andcommitted
extmod/modre: Use specific error message 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. Fixes issue micropython#17150. Signed-off-by: Jeff Epler <[email protected]>
1 parent 17951ce commit 745bec9

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

extmod/modre.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,9 @@ static mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args) {
427427
const char *re_str = mp_obj_str_get_str(args[0]);
428428
int size = re1_5_sizecode(re_str);
429429
if (size == -1) {
430+
#if MICROPY_ERROR_REPORTING >= MICROPY_ERROR_REPORTING_NORMAL
431+
mp_raise_ValueError(MP_ERROR_TEXT("regex too complex"));
432+
#endif
430433
goto error;
431434
}
432435
mp_obj_re_t *o = mp_obj_malloc_var(mp_obj_re_t, re.insts, char, size, (mp_obj_type_t *)&re_type);

0 commit comments

Comments
 (0)