BUG #19780: gtsvector_picksplit() reads uninitialized data when called with three entries
BUG #19780: gtsvector_picksplit() reads uninitialized data when called with three entries
От:
PG Bug reporting form <noreply@postgresql.org>
Дата:
The following bug has been logged on the website: Bug reference: 19780 Logged by: Alexander Lakhin Email address: exclusion@gmail.com PostgreSQL version: 19rc1 Operating system: Ubuntu 24.04 Description: The following script: CREATE TABLE t (i tsvector, j tsvector); CREATE INDEX t_idx ON t USING gist (i tsvector_ops (siglen = '1800'), j tsvector_ops); INSERT INTO t SELECT (SELECT string_agg(g::text, ' ')::tsvector FROM generate_series(1, 200) g), 'x'::tsvector FROM generate_series(1, 4); INSERT INTO t SELECT (SELECT string_agg(g::text, ' ')::tsvector FROM generate_series(1, 200) g) || 'a', 'x'::tsvector; being executed under Valgrind, triggers: ==00:00:00:57.066 1678143== Conditional jump or move depends on uninitialised value(s) ==00:00:00:57.066 1678143== at 0x48CBC35: gtsvector_picksplit (tsgistidx.c:685) ==00:00:00:57.066 1678143== by 0x493208E: FunctionCall2Coll (fmgr.c:1163) ==00:00:00:57.066 1678143== by 0x41409A3: gistUserPicksplit (gistsplit.c:433) ==00:00:00:57.066 1678143== by 0x414127B: gistSplitByKey (gistsplit.c:697) ==00:00:00:57.066 1678143== by 0x4141504: gistSplitByKey (gistsplit.c:747) ==00:00:00:57.066 1678143== by 0x4134199: gistSplit (gist.c:1483) ==00:00:00:57.066 1678143== by 0x4131D58: gistplacetopage (gist.c:316) ==00:00:00:57.066 1678143== by 0x4133D6D: gistinserttuples (gist.c:1310) ==00:00:00:57.066 1678143== by 0x4133CC7: gistinserttuple (gist.c:1263) ==00:00:00:57.066 1678143== by 0x413310D: gistdoinsert (gist.c:892) ==00:00:00:57.067 1678143== by 0x41319E7: gistinsert (gist.c:191) ==00:00:00:57.067 1678143== by 0x4184D62: index_insert (indexam.c:231) ==00:00:00:57.067 1678143== Reproduced on REL_14_STABLE .. master.
Re: BUG #19780: gtsvector_picksplit() reads uninitialized data when called with three entries
Hi Alexander,
Thanks for the report. With only two entries, the cache of the second
one is used before it is filled.
Your two column case is harmless. With one column, the index can miss
rows until REINDEX.
The attached patch fills the cache earlier and adds a test.
Thanks,
Shihao
Re: BUG #19780: gtsvector_picksplit() reads uninitialized data when called with three entries
От:
Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Дата:
Hi, On Wed, 4 Nov 2026 at 11:13, shihao zhong wrote: > > Thanks for the report. With only two entries, the cache of the second > one is used before it is filled. +1 > Your two column case is harmless. With one column, the index can miss > rows until REINDEX. > > The attached patch fills the cache earlier and adds a test. Thanks for the patch, it looks good to me. Regards, Ayush
Re: BUG #19780: gtsvector_picksplit() reads uninitialized data when called with three entries
On Wed, Nov 04, 2026 at 12:42:55AM -0500, shihao zhong wrote:
> Thanks for the report. With only two entries, the cache of the second
> one is used before it is filled.
>
> Your two column case is harmless. With one column, the index can miss
> rows until REINDEX.
>
> The attached patch fills the cache earlier and adds a test.
So the problem is this one, where we could try to read the cached data
for seed_2 but it's just not initialized yet:
datum_r = gtsvector_alloc(SIGNKEY | (cache[seed_2].allistrue ?
ALLISTRUE : 0), siglen, cache[seed_2].sign);
Calling fillcache() earlier so as datum_r and datum_l are built from
correct values is enough. Your change makes sense.
--
Michael
Re: BUG #19780: gtsvector_picksplit() reads uninitialized data when called with three entries
On Fri, Nov 06, 2026 at 04:52:21PM +0900, Michael Paquier wrote: > So the problem is this one, where we could try to read the cached data > for seed_2 but it's just not initialized yet: > datum_r = gtsvector_alloc(SIGNKEY | (cache[seed_2].allistrue ? > ALLISTRUE : 0), siglen, cache[seed_2].sign); > > Calling fillcache() earlier so as datum_r and datum_l are built from > correct values is enough. Your change makes sense. +INSERT INTO test_tsvector_wide + SELECT 'foo', decode(string_agg(md5(g::text), ''), 'hex') + FROM generate_series(1, 300) g; By the way, this test is going to piss buildfarm members that have FIPS enabled, where md5() calls fail. Could it be possible to write a test that's more portable across the board? There is a v19 RC2 in sight, and it's already late in the week here so this will have to wait until the tag of the next version is pushed around next Wednesday. It's an old issue, so a few more days will not matter. There is a fipshash() in test_setup.sql, written for portability, but perhaps we can make the test much faster by using the same tricks as test_decoding's toast.sql in terms of generation of long values? -- Michael
Re: BUG #19780: gtsvector_picksplit() reads uninitialized data when called with three entries
> By the way, this test is going to piss buildfarm members that have
> FIPS enabled, where md5() calls fail.
> FIPS enabled, where md5() calls fail.
aha. I am not aware of that.
v2 uses repeat() and sets the column to STORAGE
EXTERNAL so it stays uncompressed, like toast.sql does.
EXTERNAL so it stays uncompressed, like toast.sql does.
Thanks,
Shihao
Re: BUG #19780: gtsvector_picksplit() reads uninitialized data when called with three entries
On Sat, Nov 07, 2026 at 07:02:15PM -0500, shihao zhong wrote: > v2 uses repeat() and sets the column to STORAGE > EXTERNAL so it stays uncompressed, like toast.sql does. This version works here, and the test is much, much cheaper than in your v1 where most of the extra time was spent to build the long value. Thanks for updating the patch. (We're in freeze period for the release, so I'll get back to it in 48 hours or so after the version tags are pushed.) -- Michael
Re: BUG #19780: gtsvector_picksplit() reads uninitialized data when called with three entries
On Mon, Nov 09, 2026 at 07:25:17AM +0900, Michael Paquier wrote: > (We're in freeze period for the release, so I'll get back to it in 48 > hours or so after the version tags are pushed.) Applied down to v15 as of 1d657c6e013e. -- Michael