mirror of
https://github.com/postgres/postgres.git
synced 2025-04-20 00:42:27 +03:00
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.
This commit is contained in:
parent
b65a258a51
commit
d5b912c905
@ -83,10 +83,14 @@ static bytea *
|
|||||||
gbt_bit_xfrm(bytea *leaf)
|
gbt_bit_xfrm(bytea *leaf)
|
||||||
{
|
{
|
||||||
bytea *out = leaf;
|
bytea *out = leaf;
|
||||||
int s = INTALIGN(VARBITBYTES(leaf) + VARHDRSZ);
|
int sz = VARBITBYTES(leaf) + VARHDRSZ;
|
||||||
|
int padded_sz = INTALIGN(sz);
|
||||||
|
|
||||||
out = palloc(s);
|
out = (bytea *) palloc(padded_sz);
|
||||||
SET_VARSIZE(out, s);
|
/* initialize the padding bytes to zero */
|
||||||
|
while (sz < padded_sz)
|
||||||
|
((char *) out)[sz++] = 0;
|
||||||
|
SET_VARSIZE(out, padded_sz);
|
||||||
memcpy((void *) VARDATA(out), (void *) VARBITS(leaf), VARBITBYTES(leaf));
|
memcpy((void *) VARDATA(out), (void *) VARBITS(leaf), VARBITBYTES(leaf));
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user