Handle MAXSTRLEN consistently

Started by Zsolt Parragi3 months ago4 messageshackers
Jump to latest
#1Zsolt Parragi
zsolt.parragi@percona.com

Hello!

Commit 23d9ad77181 added additional length checks for tsvector, but it
is inconsistent at one place: most checks use toklen > MAXSTRLEN as
the error condition, but array_to_tsvector uses >=. This causes a
strange corner-case issue: we can convert a 2047 length lexeme to an
array, as tsvector_to_array allows it, but we can't convert it back
with array_to_tsvector as it errors out.

0001 is a fix for this specific case.

After looking into this further, I realized that the length handling
is also inconsistent at other places, even before the mentioned
commit.

0002 addresses the other preexisting places that used >= for errors instead of >

Attachments:

t253393_1
0001-Allow-maximum-length-lexemes-in-array_to_tsvector-ag.patchapplication/octet-stream; name=0001-Allow-maximum-length-lexemes-in-array_to_tsvector-ag.patchDownload+14-3
0002-Accept-maximum-length-lexemes-in-all-text-search-inp.patchapplication/octet-stream; name=0002-Accept-maximum-length-lexemes-in-all-text-search-inp.patchDownload+60-7
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Zsolt Parragi (#1)
Re: Handle MAXSTRLEN consistently

Zsolt Parragi <zsolt.parragi@percona.com> writes:

Commit 23d9ad77181 added additional length checks for tsvector, but it
is inconsistent at one place: most checks use toklen > MAXSTRLEN as
the error condition, but array_to_tsvector uses >=. This causes a
strange corner-case issue: we can convert a 2047 length lexeme to an
array, as tsvector_to_array allows it, but we can't convert it back
with array_to_tsvector as it errors out.

0001 is a fix for this specific case.

After looking into this further, I realized that the length handling
is also inconsistent at other places, even before the mentioned
commit.

Yeah. I noticed this inconsistency while preparing 23d9ad771,
but felt that fixing it was out of scope for a security patch.
There's a similar problem with inconsistent enforcement of
MAXSTRPOS. Attached is what I had staged to propose post-release.

regards, tom lane

Attachments:

t253393_2
v1-0001-Consistently-enforce-tsvector-tsquery-maximum-len.patchtext/x-diff; charset=us-ascii; name*0=v1-0001-Consistently-enforce-tsvector-tsquery-maximum-len.p; name*1=atchDownload+9-10
#3Zsolt Parragi
zsolt.parragi@percona.com
In reply to: Tom Lane (#2)
Re: Handle MAXSTRLEN consistently

On Wed, 12 Aug 2026, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Yeah. I noticed this inconsistency while preparing 23d9ad771,
but felt that fixing it was out of scope for a security patch.
There's a similar problem with inconsistent enforcement of
MAXSTRPOS. Attached is what I had staged to propose post-release.

Yeah, I missed that MAXSTRPOS case but it is also valid, otherwise the changes look identical.

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Zsolt Parragi (#3)
Re: Handle MAXSTRLEN consistently

Zsolt Parragi <zsolt.parragi@percona.com> writes:

On Wed, 12 Aug 2026, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Yeah. I noticed this inconsistency while preparing 23d9ad771,
but felt that fixing it was out of scope for a security patch.
There's a similar problem with inconsistent enforcement of
MAXSTRPOS. Attached is what I had staged to propose post-release.

Yeah, I missed that MAXSTRPOS case but it is also valid, otherwise the
changes look identical.

Pushed, thanks for the cross-check.

regards, tom lane