8000 Initialize padding bytes in btree_gist varbit support. · patchsoft/postgres@e31d77c · GitHub
[go: up one dir, main page]

Skip to content

Commit e31d77c

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 8607099 commit e31d77c

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
@@ -70,10 +70,14 @@ static bytea *
7070
gbt_bit_xfrm(bytea *leaf)
7171
{
7272
bytea *out = leaf;
73-
int s = INTALIGN(VARBITBYTES(leaf) + VARHDRSZ);
74-
75-
out = palloc(s);
76-
SET_VARSIZE(out, s);
73+
int sz = VARBITBYTES(leaf) + VARHDRSZ;
74+
int padded_sz = INTALIGN(sz);
75+
76+
out = (bytea *) palloc(padded_sz);
77+
/* initialize the padding bytes to zero */
78+
while (sz < padded_sz)
79+
((char *) out)[sz++] = 0;
80+
SET_VARSIZE(out, padded_sz);
7781
memcpy((void *) VARDATA(out), (void *) VARBITS(leaf), VARBITBYTES(leaf));
7882
return out;
7983
}

0 commit comments

Comments
 (0)
0