]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Guard against overflow in "left" fields of query_int and ltxtquery.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 11 May 2026 12:13:46 +0000 (05:13 -0700)
committerNoah Misch <noah@leadboat.com>
Mon, 11 May 2026 12:13:46 +0000 (05:13 -0700)
commit43451a7a2b3305571e7f8ed56d053e97acca1d1d
treedf3ab5362a2aed27c49cf4ed147ef4c4e1c6a7fc
parentb63f25bddfebc67b1e78f86341a6aecb0e9fe576
Guard against overflow in "left" fields of query_int and ltxtquery.

contrib/intarray's query_int type uses an int16 field to hold the
offset from a binary operator node to its left operand.  However, it
allows the number of nodes to be as much as will fit in MaxAllocSize,
so there is a risk of overflowing int16 depending on the precise shape
of the tree.  Simple right-associative cases like "a | b | c | ..."
work fine, so we should not solve this by restricting the overall
number of nodes.  Instead add a direct test of whether each individual
offset is too large.

contrib/ltree's ltxtquery type uses essentially the same logic and
has the same 16-bit restriction.

(The core backend's tsquery.c has a variant of this logic too, but
in that case the target field is 32 bits, so it is okay so long
as varlena datums are restricted to 1GB.)

In v16 and up, these types support soft error reporting, so we have
to complicate the recursive findoprnd function's API a bit to allow
the complaint to be reported softly.  v14/v15 don't need that.

Undocumented and overcomplicated code like this makes my head hurt,
so add some comments and simplify while at it.

Reported-by: Xint Code
Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Backpatch-through: 14
Security: CVE-2026-6473
contrib/intarray/_int_bool.c
contrib/intarray/expected/_int.out
contrib/intarray/sql/_int.sql
contrib/ltree/expected/ltree.out
contrib/ltree/ltxtquery_io.c
contrib/ltree/sql/ltree.sql