pgsql: Fix potential buffer overrun in ts_rank_cd().

From: Noah Misch <noah(at)leadboat(dot)com>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix potential buffer overrun in ts_rank_cd().
Date: 2026-11-09 14:21:48
Message-ID: E1xQQFo-000000003Fv-0Gi6@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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 <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Backpatch-through: 14
Security: CVE-2026-116317

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/c8d128858d20f424d06472a69e28b99849ed1bb6
Author: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>

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

Browse pgsql-committers by date

  From Date Subject
Next Message Noah Misch 2026-11-09 14:21:49 pgsql: Reject more unsafe names in extension script substitutions.
Previous Message Noah Misch 2026-11-09 14:21:47 pgsql: pg_basebackup: Fix use of externally-controlled format string