/* STACK_GROWTH_RATE is taken from PCRE's src/pcre2_jit_compile.c.
Going over the jitstack_max limit could trigger an int
overflow bug. */
int STACK_GROWTH_RATE = 8192;
idx_t jitstack_max = MIN (IDX_MAX, SIZE_MAX - (STACK_GROWTH_RATE - 1));
int e = pcre2_match (pc->cre, (PCRE2_SPTR) subject, search_bytes,
search_offset, options, pc->data, pc->mcontext);
if (e == PCRE2_ERROR_JIT_STACKLIMIT
&& pc->jit_stack_size <= jitstack_max / 2)
... code that computes pc->git_stack_size * 2 ...
This should avoid integer overflow in both grep and libpcre2, without
imposing arbitrary limits on what PCRE2 can do. If this more-generous
limit causes problems please let me know.
As a result of the recent changes to get grep to use PCRE2 instead of
old PCRE, the relevant code now looks like this:
- bug#51710: [PATCH] pcre: avoid overflow in PCR... Carlo Marcelo Arenas Belón
- bug#51710: [PATCH] pcre: avoid overflow i... Paul Eggert
- bug#51710: [PATCH] pcre: avoid overfl... Carlo Arenas
- bug#51710: [PATCH] pcre: avoid ov... Paul Eggert
- bug#51710: [PATCH] pcre: avoi... Paul Eggert
