agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix btree_gist's NotEqual strategy on internal index pages.
Date: Fri, 03 Jul 2026 17:50:22 +0000
Message-ID: <E1wfi1u-001CMI-1S@gemulon.postgresql.org> (raw)

Fix btree_gist's NotEqual strategy on internal index pages.

gbt_var_consistent() handled the <> (BtreeGistNotEqual) strategy without
distinguishing leaf from internal pages, unlike every other strategy.
In particular, it tried to apply the datatype-specific f_eq method,
which is completely wrong since internal keys might not have the same
representation as leaf keys.  This led to OOB reads and potentially
crashes, and most likely to wrong query results as well.

On leaf pages we can apply the inverse of what the Equal strategy does.
On internal pages, use a correct implementation of what the previous
code intended: we can descend if the query value equals both bounds,
*so long as the bounds aren't truncated*.  With truncated bounds we
don't quite know the range of what's below, so we must always descend.

Adjust the code in gbt_num_consistent() to look similar, too.  This
fixes a performance buglet in that there's no need to do two comparisons
on a leaf entry, but the main point is just to keep code consistency.

Reported-by: 王跃林 <violin0613@tju.edu.cn>
Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/AH*AvQCYKhQGVvPWi1GiU4oY.8.1781609375063.Hmail.3020001251@tju.edu.cn
Backpatch-through: 14

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/8f2a1b3d3511aa07c19c0066d75c06e81496f7c2

Modified Files
--------------
contrib/btree_gist/btree_utils_num.c | 15 +++++++++++++--
contrib/btree_gist/btree_utils_var.c | 23 +++++++++++++++++++++--
2 files changed, 34 insertions(+), 4 deletions(-)



view thread (7+ messages)  latest in thread

Message-ID: <E1wfi1u-001CMI-1S@gemulon.postgresql.org>
Permalink:  ../E1wfi1u-001CMI-1S@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1wfi1u-001CMI-1S@gemulon.postgresql.org

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 using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Fix btree_gist's NotEqual strategy on internal index pages.
  In-Reply-To: <E1wfi1u-001CMI-1S@gemulon.postgresql.org>

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

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