Re: Large regex fails with XX000 instead of a regex error

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: hi(at)joel(dot)id
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: Large regex fails with XX000 instead of a regex error
Date: 2026-12-04 23:19:35
Message-ID: 2569452.1796426375@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

hi(at)joel(dot)id writes:
> SELECT regexp_like('', string_agg(chr(19968 + i), ''))
> FROM generate_series(0, 5999) i;

> ERROR: XX000: invalid memory alloc request size 1153536480
> LOCATION: MemoryContextSizeFailure, mcxt.c:1180

I really cannot get excited about this. Yes, we could make it
say REG_ETOOBIG instead, but at the price of putting a very
Postgres-specific limit calculation into the guts of the regex
engine. I still have a vision of that code someday being an
independent library, so I'd rather not do that.

Another option perhaps could be to allow MALLOC_ARRAY to
specify MCXT_ALLOC_HUGE, so that the INT_MAX limit would be
meaningful. But that would come with its own disadvantages,
for instance making it easier to incur the wrath of the OOM
killer. I wouldn't want to go there without a fair amount
of analysis.

On the whole I don't find this worth worrying about.
It doesn't look like something that will be hit by
non-contrived regexes.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2026-12-04 23:27:58 Re: Memory leak in InitMaterializedSRF when a set-returning function is called once per row (15+)
Previous Message Robert Haas 2026-12-04 23:08:31 Re: BUG #19519: REPACK can fail due to missing chunk for toast value