Skip to content

Commit 540ac7c

Browse files
committed
Initialize padding bytes in btree_gist varbit support.
The code expands a varbit gist leaf key to a node key by copying the bit data twice in a varlen datum, as both the lower and upper key. The lower key was expanded to INTALIGN size, but the padding bytes were not initialized. That's a problem because when the lower/upper keys are compared, the padding bytes are used compared too, when the values are otherwise equal. That could lead to incorrect query results. REINDEX is advised for any btree_gist indexes on bit or bit varying data type, to fix any garbage padding bytes on disk. Per Valgrind, reported by Andres Freund. Backpatch to all supported versions.
1 parent 5a90ac2 commit 540ac7c

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

contrib/btree_gist/btree_bit.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,14 @@ static bytea *
7575
gbt_bit_xfrm(bytea *leaf)
7676
{
7777
bytea *out = leaf;
78-
int s = INTALIGN(VARBITBYTES(leaf) + VARHDRSZ);
79-
80-
out = palloc(s);
81-
SET_VARSIZE(out, s);
78+
int sz = VARBITBYTES(leaf) + VARHDRSZ;
79+
int padded_sz = INTALIGN(sz);
80+
81+
out = (bytea *) palloc(padded_sz);
82+
/* initialize the padding bytes to zero */
83+
while (sz < padded_sz)
84+
((char *) out)[sz++] = 0;
85+
SET_VARSIZE(out, padded_sz);
8286
memcpy((void *) VARDATA(out), (void *) VARBITS(leaf), VARBITBYTES(leaf));
8387
return out;
8488
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy