From 745bec9ce3cc4c95d8e80fcc8f64ffecde1d91bc Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Sun, 1 Jun 2025 18:47:36 +0200 Subject: [PATCH] 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 #17150. Signed-off-by: Jeff Epler --- extmod/modre.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/extmod/modre.c b/extmod/modre.c index 1a118009cb..d17ec68d50 100644 --- a/extmod/modre.c +++ b/extmod/modre.c @@ -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);