BUG #18708: regex problem: (?:[^\d\D]){0} asserts with "lp->nouts == 0 && rp->nins == 0"

The Post Office <noreply@postgresql.org>

From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: dhyan@nataraj.su
Date: 2024-11-14T12:29:12Z
Lists: pgsql-bugs
The following bug has been logged on the website:

Bug reference:      18708
Logged by:          Nikolay Shaplov (PostgresPro)
Email address:      dhyan@nataraj.su
PostgreSQL version: 16.4
Operating system:   Debian 12
Description:        

Hi! 

We've found a bug: 

If you run 

SELECT '' ~ '(?:[^\d\D]){0}'; 

it will assert with  "lp->nouts == 0 && rp->nins == 0"

This behavior have been introduced in 2a0af7fe460 commit.

This bug have been found while fuzzing jsonpath_in function, and then
narrowed down to regex problem. Thanks to Andrey Bille for help with
narrowing sample down and finding commit that caused the problem.

Commits

  1. Fix recently-exposed portability issue in regex optimization.

  2. Avoid assertion due to disconnected NFA sub-graphs in regex parsing.

  3. Fix recovery conflict SIGUSR1 handling.

  4. Redesign interrupt/cancel API for regex engine.

  5. Use MemoryContext API for regex memory management.

  6. Invent "rainbow" arcs within the regex engine.