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_17_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/7f8424ece5d078becf0c018ef33e3866218de023 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(-)
