Prevent stack overflow in exprLocation while parsing long queries

Started by Zsolt Parragi4 days ago2 messageshackers

Thread notes

1 note#bug
hackorum-bot#bug
hackorum-bot
2 days ago

@global #bug

#bug
Jump to latest
#1Zsolt Parragi
zsolt.parragi@percona.com

Hello

In a thread about repack [1]/messages/by-id/awVFP-EHuqyMYv51@alvherre.pgsql Alvaro pointed out that the parser
support for psql is a hack, and since I was already interested in
making the parser available as a library for different projects I
decided to take a look into that.

Shortly after starting, Claude pointed out a trivial bug where a long
chain can cause a stack overflow crash during error reporting.

Since this requires a 1 line fix, I attached a patch for it.

I'm not sure if we want to add a test case for something like this,
but since it doesn't take much time to run or isn't too complex, the
patch includes one.

[1]: /messages/by-id/awVFP-EHuqyMYv51@alvherre.pgsql

Attachments:

t259735_1
v1-0001-Prevent-stack-overflow-in-exprLocation.patchapplication/octet-stream; name=v1-0001-Prevent-stack-overflow-in-exprLocation.patchDownload+28-1
#2Heikki Linnakangas
hlinnaka@iki.fi
In reply to: Zsolt Parragi (#1)
Re: Prevent stack overflow in exprLocation while parsing long queries

On 24/11/2026 19:36, Zsolt Parragi wrote:

Hello

In a thread about repack [1] Alvaro pointed out that the parser
support for psql is a hack, and since I was already interested in
making the parser available as a library for different projects I
decided to take a look into that.

Shortly after starting, Claude pointed out a trivial bug where a long
chain can cause a stack overflow crash during error reporting.

Since this requires a 1 line fix, I attached a patch for it.

I'm not sure if we want to add a test case for something like this,
but since it doesn't take much time to run or isn't too complex, the
patch includes one.

Applied, thanks. I didn't commit the test, it'd be excessive to include
a test for every possible recursion in the system. But thanks for
including it anyway, it was useful for reviewing.

- Heikki