Fix potential buffer overrun in ts_rank_cd().

get_docrep() assumed there could be no more QueryItems per group
than there are lexemes in the input tsvector.  That's true with valid
tsvector input, which will never show duplicate positions for any
lexeme.  But with duplicate positions it's possible to overrun the
allocated space.  Guard against that by dropping items if there are
more than we expect (it doesn't seem worth working harder than that).

The submitted test case that reached this constructed an invalid
tsvector by dint of starting with one, namely a tsvector containing
a zero position, which tsvectorrecv() failed to prevent before
10cc5aa96.  It's not clear whether the problem is reachable without
that.

Reported-by: Anthropic OSS program
Author: Anthropic OSS program
Reviewed-by: Tom Lane <[email protected]>
Backpatch-through: 14
Security: CVE-2026-116317

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/2d7573b0098d035db01a742bb1475d4a7f45ff57
Author: Tom Lane <[email protected]>

Modified Files
--------------
src/backend/utils/adt/tsrank.c | 14 ++++++++++++--
src/include/tsearch/ts_type.h  |  2 +-
2 files changed, 13 insertions(+), 3 deletions(-)

Reply via email to