Skip to content

Commit 08905bf

Browse files
authored
Handle wrong user-supplied input in bloom1_hash function (#9973)
We can't use Ensure to verify the user-supplied arguments.
1 parent 8a10eb4 commit 08905bf

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

tsl/src/compression/batch_metadata_builder_bloom1.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -903,10 +903,14 @@ bloom1_hash(PG_FUNCTION_ARGS)
903903
TupleDesc tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
904904

905905
num_columns = tupdesc->natts;
906-
Ensure(num_columns <= MAX_BLOOM_FILTER_COLUMNS,
907-
"composite bloom filter supports at most %d columns, got %d",
908-
MAX_BLOOM_FILTER_COLUMNS,
909-
num_columns);
906+
if (num_columns > MAX_BLOOM_FILTER_COLUMNS)
907+
{
908+
ereport(ERROR,
909+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
910+
errmsg("composite bloom filter supports at most %d columns, got %d",
911+
MAX_BLOOM_FILTER_COLUMNS,
912+
num_columns)));
913+
}
910914

911915
for (int i = 0; i < num_columns; i++)
912916
{

tsl/test/expected/compress_bloom_sparse_debug.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,6 @@ SELECT _timescaledb_functions.bloom1_contains(NULL, pg_catalog.record_in(null::c
234234
-----------------
235235
f
236236

237+
-- The hash function is callable by user, so must return proper error
238+
SELECT _timescaledb_functions.bloom1_hash(ROW(1, 2, 3, 4, 5, 6, 7, 8, 9));
239+
ERROR: composite bloom filter supports at most 8 columns, got 9

tsl/test/sql/compress_bloom_sparse_debug.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,8 @@ SELECT _timescaledb_functions.bloom1_contains('\xd098c885f08468eb8916751d947f248
170170
-- both args NULL but second arg obfuscated through record_in
171171
SELECT _timescaledb_functions.bloom1_contains(NULL, pg_catalog.record_in(null::cstring, 23::oid, 12::int4));
172172

173+
174+
-- The hash function is callable by user, so must return proper error
175+
SELECT _timescaledb_functions.bloom1_hash(ROW(1, 2, 3, 4, 5, 6, 7, 8, 9));
176+
177+

0 commit comments

Comments
 (0)