pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: kehan5800@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #19748: tsvectorrecv accepts duplicate lexemes and position 0 that tsvectorin rejects
Date: Mon, 05 Oct 2026 14:48:11 -0400
Message-ID: <1091610.1791226091@sss.pgh.pa.us> (raw)
In-Reply-To: <19748-6075f0508fa1ffc0@postgresql.org>
References: <19748-6075f0508fa1ffc0@postgresql.org>

PG Bug reporting form <noreply@postgresql.org> writes:
> tsvectorrecv() (src/backend/utils/adt/tsvector.c:446) has this comment
> (tsvector.c:552-556):

>     * Enforce that datalen is still within MAXSTRPOS, ie the last lexeme
>     * didn't go past that.  We could allow that, since no "pos" field
>     * overflowed, but tsvectorrecv shouldn't accept values that other
>     * tsvector-constructing routines wouldn't.

> Two checks are still missing relative to tsvectorin():

> 1. Duplicate lexemes are not merged. tsvectorin() runs uniqueentry()
>    (tsvector.c:265). tsvectorrecv() detects "compareentry(...) <= 0"
>    (tsvector.c:514-517), but only sorts (tsvector.c:563); equal entries
>    stay. The result is a tsvector with repeated lexemes, which no other
>    constructor produces, and which silently changes on a text round trip.

Hmph.  Making that happen would be a lot of mess, since that'd require
also merging and de-duping positions for equal lexemes, and the de-dup
logic used by tsvectorin() can't be re-used because it doesn't work on
the same data representation.  But it seems to me that tsvectorrecv()
is being quite schizophrenic here: it will let you be sloppy about
lexeme order, but not about duplicated or out-of-order positions.
I don't see a good reason for it to be forgiving about either thing.
So my proposal is to just throw an error if the lexeme sequence isn't
strictly increasing, as it already does for positions.  That is
probably not something to back-patch, but this issue is surely not
important enough to worry about back-patching.

> 2. The first position is never checked. tsvectorin() rejects position 0
>    ("wrong position info in tsvector", tsvector_parser.c:334); the receive
>    loop only checks that positions ascend for j > 0 (tsvector.c:540-545),
>    so a leading position 0 is accepted.

Agreed, that's an oversight.

			regards, tom lane






view thread (3+ messages)  latest in thread

Message-ID: <1091610.1791226091@sss.pgh.pa.us>
Permalink:  ../1091610.1791226091@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1091610.1791226091@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, kehan5800@gmail.com
  Subject: Re: BUG #19748: tsvectorrecv accepts duplicate lexemes and position 0 that tsvectorin rejects
  In-Reply-To: <1091610.1791226091@sss.pgh.pa.us>
  References: <19748-6075f0508fa1ffc0@postgresql.org> <1091610.1791226091@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox