Subject: bug#43862: [PATCH] grep: set RE_NO_SUB for calling regex only to check syntax

From: Norihiro Tanaka <[email-masked]>
Date: Mon, 02 Nov 2020 13:21:42 +0900

On Sun, 1 Nov 2020 11:39:55 -0800
Jim Meyering <[email-masked]> wrote:

> We must accept the fact that extreme regular expressions will cause
> resource exhaustion like that when processed by classical regex_*
> functions. This is yet another good reason to prefer PCRE and to use
> grep's -P option. In that case, it fails like this:
> 
> $ printf '(%080000d)\n' | sed 's/0/|/g' |grep -Pf- /dev/null
> grep: regular expression is too large
> 
> I have just pushed your patch, but without adding a test.

I also investigated the slowdown, and I reached the same view as you.

The regex consumes a lot of memory for patterns with normous epsilon
closures.