postgres/contrib/intarray
Tom Lane e708ffe79d Fix GIN's shimTriConsistentFn to not corrupt its input.
Commit 0f21db36d made an assumption that GIN triConsistentFns
would not modify their input entryRes[] arrays.  But in fact,
the "shim" triConsistentFn that we use for opclasses that don't
supply their own did exactly that, potentially leading to wrong
answers from a GIN index search.  Through bad luck, none of the
test cases that we have for such opclasses exposed the bug.

One response to this could be that the assumption of consistency check
functions not modifying entryRes[] arrays is a bad one, but it still
seems reasonable to me.  Notably, shimTriConsistentFn is itself
assuming that with respect to the underlying boolean consistentFn,
so it's sure being self-centered in supposing that it gets to do so.

Fortunately, it's quite simple to fix shimTriConsistentFn to restore
the entry-time state of entryRes[], so let's do that instead.

This issue doesn't affect any core GIN opclasses, since they all
supply their own triConsistentFns.  It does affect contrib modules
btree_gin, hstore, and intarray.

Along the way, I (tgl) noticed that shimTriConsistentFn failed to
pick up on a "recheck" flag returned by its first call to the boolean
consistentFn.  This may be only a latent problem, since it would be
unlikely for a consistentFn to set recheck for the all-false case
and not any other cases.  (Indeed, none of our contrib modules do
that.)  Nonetheless, it's formally wrong.

Reported-by: Vinod Sridharan <vsridh90@gmail.com>
Author: Vinod Sridharan <vsridh90@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAFMdLD7XzsXfi1+DpTqTgrD8XU0i2C99KuF=5VHLWjx4C1pkcg@mail.gmail.com
Backpatch-through: 13
2025-04-12 12:28:02 -04:00
..
bench Update copyright for 2025 2025-01-01 11:21:55 -05:00
data Fix integer-overflow problem in intarray's g_int_decompress(). 2024-01-07 15:19:50 -05:00
expected Fix GIN's shimTriConsistentFn to not corrupt its input. 2025-04-12 12:28:02 -04:00
sql Fix GIN's shimTriConsistentFn to not corrupt its input. 2025-04-12 12:28:02 -04:00
_int_bool.c Remove useless casts to (void *) 2024-11-28 08:27:20 +01:00
_int_gin.c Make the order of the header file includes consistent in contrib modules. 2019-10-24 08:05:34 +05:30
_int_gist.c Fix integer-overflow problem in intarray's g_int_decompress(). 2024-01-07 15:19:50 -05:00
_int_op.c Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
_int_selfuncs.c Update copyright for 2025 2025-01-01 11:21:55 -05:00
_int_tool.c Specialize intarray sorting 2025-02-18 11:04:55 +07:00
_int.h Specialize intarray sorting 2025-02-18 11:04:55 +07:00
_intbig_gist.c Use new overflow-safe integer comparison functions. 2024-02-16 14:05:36 -06:00
.gitignore
intarray--1.1--1.2.sql Make contrib modules' installation scripts more secure. 2020-08-10 10:44:42 -04:00
intarray--1.2--1.3.sql Implement operator class parameters 2020-03-30 19:17:23 +03:00
intarray--1.2.sql Update extensions with GIN/GIST support for parallel query. 2016-06-14 13:34:37 -04:00
intarray--1.3--1.4.sql Remove <@ from contrib/intarray's GiST operator classes. 2020-08-08 17:26:29 -04:00
intarray--1.4--1.5.sql Remove deprecated containment operators for contrib types. 2021-03-05 10:45:41 -05:00
intarray--1.0--1.1.sql Add selectivity estimation functions for intarray operators. 2015-07-21 20:59:24 +03:00
intarray.control Remove deprecated containment operators for contrib types. 2021-03-05 10:45:41 -05:00
Makefile Remove deprecated containment operators for contrib types. 2021-03-05 10:45:41 -05:00
meson.build Update copyright for 2025 2025-01-01 11:21:55 -05:00