Skip to content

Commit 80afb62

Browse files
committed
Fixes in bloom contrib module
Looking at result of buildfarm member jaguarundi it seems to me that BloomOptions isn't inited sometime, but I don't see yet how it's possible. Nevertheless, check of signature length's is missed, so, add a limit of it. Also add missed GenericXLogAbort() in case of already deleted page in vacuum + minor code refactoring.
1 parent c22650c commit 80afb62

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

contrib/bloom/bloom.h

+6
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ typedef BloomPageOpaqueData *BloomPageOpaque;
6363
#define BLOOM_METAPAGE_BLKNO (0)
6464
#define BLOOM_HEAD_BLKNO (1) /* first data page */
6565

66+
/*
67+
* Maximum of bloom signature length in uint16. Actual value
68+
* is 512 bytes
69+
*/
70+
#define MAX_BLOOM_LENGTH (256)
71+
6672
/* Bloom index options */
6773
typedef struct BloomOptions
6874
{

contrib/bloom/blutils.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ myRand()
177177
/*
178178
* Compute x = (7^5 * x) mod (2^31 - 1)
179179
* without overflowing 31 bits:
180-
* (2^31 - 1) = 127773 * (7^5) + 2836
180+
* (2^31 - 1) = 127773 * (7^5) + 2836
181181
* From "Random number generators: good ones are hard to find",
182182
* Park and Miller, Communications of the ACM, vol. 31, no. 10,
183183
* October 1988, p. 1195.
@@ -370,8 +370,11 @@ adjustBloomOptions(BloomOptions *opts)
370370
/* Default length of bloom filter is 5 of 16-bit integers */
371371
if (opts->bloomLength <= 0)
372372
opts->bloomLength = 5;
373-
else
374-
opts->bloomLength = opts->bloomLength;
373+
else if (opts->bloomLength > MAX_BLOOM_LENGTH)
374+
ereport(ERROR,
375+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
376+
errmsg("length of bloom signature (%d) is greater than maximum %d",
377+
opts->bloomLength, MAX_BLOOM_LENGTH)));
375378

376379
/* Check singnature length */
377380
for (i = 0; i < INDEX_MAX_KEYS; i++)
@@ -382,7 +385,7 @@ adjustBloomOptions(BloomOptions *opts)
382385
* with 2 bits default.
383386
*/
384387
if (opts->bitSize[i] <= 0
385-
|| opts->bitSize[i] >= opts->bloomLength * sizeof(SignType))
388+
|| opts->bitSize[i] >= opts->bloomLength * sizeof(SignType) * BITS_PER_BYTE)
386389
opts->bitSize[i] = 2;
387390
}
388391
}

contrib/bloom/blvacuum.c

+7-6
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,15 @@ blbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats,
7070
if (BloomPageIsDeleted(page))
7171
{
7272
UnlockReleaseBuffer(buffer);
73+
GenericXLogAbort(gxlogState);
7374
CHECK_FOR_INTERRUPTS();
7475
continue;
7576
}
7677

7778
/* Iterate over the tuples */
78-
itup = BloomPageGetTuple(&state, page, 1);
79-
itupPtr = BloomPageGetTuple(&state, page, 1);
80-
itupEnd = BloomPageGetTuple(&state, page, BloomPageGetMaxOffset(page) + 1);
79+
itup = itupPtr = BloomPageGetTuple(&state, page, FirstOffsetNumber);
80+
itupEnd = BloomPageGetTuple(&state, page,
81+
OffsetNumberNext(BloomPageGetMaxOffset(page)));
8182
while (itup < itupEnd)
8283
{
8384
/* Do we have to delete this tuple? */
@@ -104,10 +105,10 @@ blbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats,
104105
itup = BloomPageGetNextTuple(&state, itup);
105106
}
106107

107-
Assert(itupPtr == BloomPageGetTuple(&state, page, BloomPageGetMaxOffset(page) + 1));
108+
Assert(itupPtr == BloomPageGetTuple(&state, page,
109+
OffsetNumberNext(BloomPageGetMaxOffset(page))));
108110

109-
if (!BloomPageIsDeleted(page) &&
110-
BloomPageGetFreeSpace(&state, page) > state.sizeOfBloomTuple &&
111+
if (BloomPageGetFreeSpace(&state, page) > state.sizeOfBloomTuple &&
111112
countPage < BloomMetaBlockN)
112113
notFullPage[countPage++] = blkno;
113114

0 commit comments

Comments
 (0)