[PATCH] posix: Don't unnecessarily duplicate the parse tree in regcomp [BZ #20095]
Florian Weimer
fweimer@redhat.com
Fri Oct 17 06:44:33 GMT 2025
* Collin Funk:
> Currently regcomp duplicates the the parse tree for each repetition
> operator. This patch avoids the duplication when the previous repetition
> operator is the same as the current operator. This prevents you from
> quickly exhausting the system's memory. Here is an example with GNU grep
> before and after this change:
>
> $ (ulimit -v 10000000 \
> && grep -Ec 'a++++++++++++++++++++++++' COPYING)
> grep: Memory exhausted
> $ (ulimit -v 10000000 \
> && ./src/grep -Ec 'a++++++++++++++++++++++++' COPYING)
> 509
Does this change really make a difference? It seems we still run out of
memory for ?+?+?+… and similar patterns.
Thanks,
Florian
More information about the Libc-alpha
mailing list