diff --git a/contrib/bloom/bloom.h b/contrib/bloom/bloom.h
index 63095723c9a55331cc0bc97e3f1f77a5b8a813d5..fb0bc07f2846d9b58b70f23ac7cea8c708985ffa 100644
--- a/contrib/bloom/bloom.h
+++ b/contrib/bloom/bloom.h
@@ -63,6 +63,12 @@ typedef BloomPageOpaqueData *BloomPageOpaque;
 #define BLOOM_METAPAGE_BLKNO	(0)
 #define BLOOM_HEAD_BLKNO		(1)		/* first data page */
 
+/*
+ * Maximum of bloom signature length in uint16. Actual value
+ * is 512 bytes
+ */
+#define MAX_BLOOM_LENGTH		(256)
+
 /* Bloom index options */
 typedef struct BloomOptions
 {
diff --git a/contrib/bloom/blutils.c b/contrib/bloom/blutils.c
index b86f51fb8255994301a723b642aed5b287f08040..f301f415ab21debc115df707eedba9fb069b9d13 100644
--- a/contrib/bloom/blutils.c
+++ b/contrib/bloom/blutils.c
@@ -177,7 +177,7 @@ myRand()
 	/*
 	 * Compute x = (7^5 * x) mod (2^31 - 1)
 	 * without overflowing 31 bits:
-	 *      (2^31 - 1) = 127773 * (7^5) + 2836
+	 *		(2^31 - 1) = 127773 * (7^5) + 2836
 	 * From "Random number generators: good ones are hard to find",
 	 * Park and Miller, Communications of the ACM, vol. 31, no. 10,
 	 * October 1988, p. 1195.
@@ -370,8 +370,11 @@ adjustBloomOptions(BloomOptions *opts)
 	/* Default length of bloom filter is 5 of 16-bit integers */
 	if (opts->bloomLength <= 0)
 		opts->bloomLength = 5;
-	else
-		opts->bloomLength = opts->bloomLength;
+	else if (opts->bloomLength > MAX_BLOOM_LENGTH)
+		ereport(ERROR,
+				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+				 errmsg("length of bloom signature (%d) is greater than maximum %d",
+						opts->bloomLength, MAX_BLOOM_LENGTH)));
 
 	/* Check singnature length */
 	for (i = 0; i < INDEX_MAX_KEYS; i++)
@@ -382,7 +385,7 @@ adjustBloomOptions(BloomOptions *opts)
 		 * with 2 bits default.
 		 */
 		if (opts->bitSize[i] <= 0
-			|| opts->bitSize[i] >= opts->bloomLength * sizeof(SignType))
+			|| opts->bitSize[i] >= opts->bloomLength * sizeof(SignType) * BITS_PER_BYTE)
 			opts->bitSize[i] = 2;
 	}
 }
diff --git a/contrib/bloom/blvacuum.c b/contrib/bloom/blvacuum.c
index d976ce53305ebf82fade0ea967947fc43c4a3a6d..9fee3c1294fbeb99637f7c48e08942a5e2b5f2c5 100644
--- a/contrib/bloom/blvacuum.c
+++ b/contrib/bloom/blvacuum.c
@@ -70,14 +70,15 @@ blbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats,
 		if (BloomPageIsDeleted(page))
 		{
 			UnlockReleaseBuffer(buffer);
+			GenericXLogAbort(gxlogState);
 			CHECK_FOR_INTERRUPTS();
 			continue;
 		}
 
 		/* Iterate over the tuples */
-		itup = BloomPageGetTuple(&state, page, 1);
-		itupPtr = BloomPageGetTuple(&state, page, 1);
-		itupEnd = BloomPageGetTuple(&state, page, BloomPageGetMaxOffset(page) + 1);
+		itup = itupPtr = BloomPageGetTuple(&state, page, FirstOffsetNumber);
+		itupEnd = BloomPageGetTuple(&state, page,
+								OffsetNumberNext(BloomPageGetMaxOffset(page)));
 		while (itup < itupEnd)
 		{
 			/* Do we have to delete this tuple? */
@@ -104,10 +105,10 @@ blbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats,
 			itup = BloomPageGetNextTuple(&state, itup);
 		}
 
-		Assert(itupPtr == BloomPageGetTuple(&state, page, BloomPageGetMaxOffset(page) + 1));
+		Assert(itupPtr == BloomPageGetTuple(&state, page,
+								OffsetNumberNext(BloomPageGetMaxOffset(page))));
 
-		if (!BloomPageIsDeleted(page) &&
-			BloomPageGetFreeSpace(&state, page) > state.sizeOfBloomTuple &&
+		if (BloomPageGetFreeSpace(&state, page) > state.sizeOfBloomTuple &&
 			countPage < BloomMetaBlockN)
 			notFullPage[countPage++] = blkno;