pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feedAssert in test_bms_membership();
5+ messages / 4 participants
[nested] [flat]
* Assert in test_bms_membership();
@ 2026-09-08 11:52 Ilya Cherdakov <i.cherdakov.pg@gmail.com>
2026-09-08 13:14 ` Re: Assert in test_bms_membership(); Andres Freund <andres@anarazel.de>
0 siblings, 1 reply; 5+ messages in thread
From: Ilya Cherdakov @ 2026-09-08 11:52 UTC (permalink / raw)
To: pgsql-hackers; +Cc: drowley@postgresql.org
Postgresql 19 added a new module, src/test/modules/test_bitmapset.
It contains the function test_bms_membership(), which is a wrapper
around bms_membership. Passing some string that are not valid Bitmapset
representation to this function will result to assert. For example
SELECT test_bms_membership('b 1 2)');
or
SELECT test_bms_membership('true');
[backtrace.txt]
|The assertion appears to occur becaus| in
#define TEXT_TO_BITMAPSET(str) (test_bitmapset.c:91) casts to Bitmapset*
without type checking, using stringToNode, which obviously can return
types other than T_Bitmapset (read.c:247). This pointer, with the wrong
type, is then passed to bms_membership, where it fails the assert
with type checking (bitmapset.c:905).
The fix simply adds a check whether the type is valid or not,
as done in the bms_is_valid_set()(bitmapset.c:87) function.
---
Best regards,
Ilya Cherdakov
Postgres Professional: https://postgrespro.com
Attachments:
backtrace.txt (text/plain, 3.1K) download
(gdb) bt
#0 __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at ./nptl/pthread_kill.c:44
#1 0x00007fbfc389f9ff in __pthread_kill_internal (threadid=<optimized out>, signo=6) at ./nptl/pthread_kill.c:89
#2 0x00007fbfc384acc2 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#3 0x00007fbfc38334ac in __GI_abort () at ./stdlib/abort.c:77
#4 0x000055b02387ec15 in ExceptionalCondition (conditionName=conditionName@entry=0x55b0238f5bee "bms_is_valid_set(a)", fileName=fileName@entry=0x55b0238f5ec4 "bitmapset.c",
lineNumber=lineNumber@entry=906) at assert.c:65
#5 0x000055b02357867d in bms_membership (a=<optimized out>) at bitmapset.c:906
#6 0x00007fbfc3db9e21 in test_bms_membership (fcinfo=<optimized out>) at test_bitmapset.c:254
#7 0x000055b0235138a1 in ExecInterpExpr (state=0x55b02cbf92c0, econtext=0x55b02cbf8f68, isnull=<optimized out>) at execExprInterp.c:936
#8 0x000055b023552475 in ExecEvalExprNoReturn (state=0x55b02cbf92c0, econtext=0x55b02cbf8f68) at ../../../src/include/executor/executor.h:431
#9 ExecEvalExprNoReturnSwitchContext (state=0x55b02cbf92c0, econtext=0x55b02cbf8f68) at ../../../src/include/executor/executor.h:472
#10 ExecProject (projInfo=0x55b02cbf92b8) at ../../../src/include/executor/executor.h:504
#11 ExecResult (pstate=<optimized out>) at nodeResult.c:135
#12 0x000055b023517aeb in ExecProcNode (node=0x55b02cbf8e58) at ../../../src/include/executor/executor.h:327
#13 ExecutePlan (queryDesc=0x55b02cb1f3c0, operation=CMD_SELECT, sendTuples=true, numberTuples=0, direction=<optimized out>, dest=0x55b02cbf77a0) at execMain.c:1776
#14 standard_ExecutorRun (queryDesc=0x55b02cb1f3c0, direction=<optimized out>, count=0) at execMain.c:377
#15 0x000055b0237236d8 in PortalRunSelect (portal=portal@entry=0x55b02cb7f600, forward=forward@entry=true, count=0, count@entry=9223372036854775807, dest=dest@entry=0x55b02cbf77a0) at pquery.c:917
#16 0x000055b023724cee in PortalRun (portal=portal@entry=0x55b02cb7f600, count=count@entry=9223372036854775807, isTopLevel=isTopLevel@entry=true, dest=dest@entry=0x55b02cbf77a0,
altdest=altdest@entry=0x55b02cbf77a0, qc=qc@entry=0x7fffcda59a80) at pquery.c:761
#17 0x000055b02372082a in exec_simple_query (query_string=0x55b02caf6e40 "SELECT test_bms_membership('true');") at postgres.c:1297
#18 0x000055b023722487 in PostgresMain (dbname=<optimized out>, username=<optimized out>) at postgres.c:4946
#19 0x000055b02371c54d in BackendMain (startup_data=<optimized out>, startup_data_len=<optimized out>) at backend_startup.c:124
#20 0x000055b02365f4c9 in postmaster_child_launch (child_type=<optimized out>, child_slot=1, startup_data=startup_data@entry=0x7fffcda59f20, startup_data_len=startup_data_len@entry=24,
client_sock=client_sock@entry=0x7fffcda59f40) at launch_backend.c:268
#21 0x000055b023662f70 in BackendStartup (client_sock=0x7fffcda59f40) at postmaster.c:3643
#22 ServerLoop () at postmaster.c:1729
#23 0x000055b0236649ec in PostmasterMain (argc=argc@entry=3, argv=argv@entry=0x55b02caf1640) at postmaster.c:1416
#24 0x000055b023316d2a in main (argc=3, argv=0x55b02caf1640) at main.c:227
0001-Validate-Bitmapset-input-in-test_bitmapset.patch (text/plain, 1.5K) download
From d4caaef47d9821636c5629d2feaf02cfc60a96bc Mon Sep 17 00:00:00 2001
From: Ilya Cherdakov <i.cherdakov@postgrespro.ru>
Date: Tue, 8 Sep 2026 14:13:16 +0300
Subject: [PATCH] Validate Bitmapset input in test_bitmapset
---
.../modules/test_bitmapset/test_bitmapset.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/src/test/modules/test_bitmapset/test_bitmapset.c b/src/test/modules/test_bitmapset/test_bitmapset.c
index af8c664949e..1fc6d618611 100644
--- a/src/test/modules/test_bitmapset/test_bitmapset.c
+++ b/src/test/modules/test_bitmapset/test_bitmapset.c
@@ -88,14 +88,27 @@ PG_FUNCTION_INFO_V1(test_random_offset_operations);
/* Encode/Decode to/from TEXT and Bitmapset */
#define BITMAPSET_TO_TEXT(bms) cstring_to_text(nodeToString(bms))
-#define TEXT_TO_BITMAPSET(str) ((Bitmapset *) stringToNode(text_to_cstring(str)))
+
+static Bitmapset *
+text_to_bitmapset(text *arg)
+{
+ Node *node;
+
+ node = stringToNode(text_to_cstring(arg));
+
+ if (node != NULL && !IsA(node, Bitmapset))
+ ereport(ERROR,
+ (errmsg("input is not a Bitmapset")));
+
+ return (Bitmapset *) node;
+}
/*
* Helper macro to fetch text parameters as Bitmapsets. SQL-NULL means empty
* set.
*/
#define PG_ARG_GETBITMAPSET(n) \
- (PG_ARGISNULL(n) ? NULL : TEXT_TO_BITMAPSET(PG_GETARG_TEXT_PP(n)))
+ (PG_ARGISNULL(n) ? NULL : text_to_bitmapset(PG_GETARG_TEXT_PP(n)))
/*
* Helper macro to handle converting sets back to text, returning the
--
2.47.3
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Assert in test_bms_membership();
2026-09-08 11:52 Assert in test_bms_membership(); Ilya Cherdakov <i.cherdakov.pg@gmail.com>
@ 2026-09-08 13:14 ` Andres Freund <andres@anarazel.de>
2026-09-08 19:32 ` Re: Assert in test_bms_membership(); Zsolt Parragi <zsolt.parragi@percona.com>
0 siblings, 1 reply; 5+ messages in thread
From: Andres Freund @ 2026-09-08 13:14 UTC (permalink / raw)
To: Ilya Cherdakov <i.cherdakov.pg@gmail.com>; +Cc: pgsql-hackers; drowley@postgresql.org
Hi,
On 2026-09-08 18:52:58 +0700, Ilya Cherdakov wrote:
> Postgresql 19 added a new module, src/test/modules/test_bitmapset.
> It contains the function test_bms_membership(), which is a wrapper
> around bms_membership. Passing some string that are not valid Bitmapset
> representation to this function will result to assert. For example
>
> SELECT test_bms_membership('b 1 2)');
> or
> SELECT test_bms_membership('true');
>
> [backtrace.txt]
>
> |The assertion appears to occur becaus| in
> #define TEXT_TO_BITMAPSET(str) (test_bitmapset.c:91) casts to Bitmapset*
> without type checking, using stringToNode, which obviously can return
> types other than T_Bitmapset (read.c:247). This pointer, with the wrong
> type, is then passed to bms_membership, where it fails the assert
> with type checking (bitmapset.c:905).
>
> The fix simply adds a check whether the type is valid or not,
> as done in the bms_is_valid_set()(bitmapset.c:87) function.
Perhaps a stupid question, but: Who cares? This is a test module, intended to
write tests for bms_*. I feel like we have much better things to do than to
prevent somebody triggering asserts while write tests in an intentionally bad
way?
Greetings,
Andres Freund
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Assert in test_bms_membership();
2026-09-08 11:52 Assert in test_bms_membership(); Ilya Cherdakov <i.cherdakov.pg@gmail.com>
2026-09-08 13:14 ` Re: Assert in test_bms_membership(); Andres Freund <andres@anarazel.de>
@ 2026-09-08 19:32 ` Zsolt Parragi <zsolt.parragi@percona.com>
2026-09-08 20:09 ` Re: Assert in test_bms_membership(); Andres Freund <andres@anarazel.de>
0 siblings, 1 reply; 5+ messages in thread
From: Zsolt Parragi @ 2026-09-08 19:32 UTC (permalink / raw)
To: Andres Freund <andres@anarazel.de>; +Cc: pgsql-hackers@lists.postgresql.org, Ilya Cherdakov <i.cherdakov.pg@gmail.com>
Hello!
This seem to be 0002 from a patchset I submitted yesterday[1].
> Perhaps a stupid question, but: Who cares?
My reasoning for this was that the other test module that has the same
issue (test_extensible) states that it is an example for extension
developers:
This module can be used as a template for developers willing to develop
their own extensions. "Writing a Custom Scan Provider" covers the
documentation for custom scans.
So I thought a small fix is a good improvement there, and then
test_bms_membership was an easy follow up because it's the same thing.
[1]: https://www.postgresql.org/message-id/CAN4CZFOTQXMZvuPxweO4Fm7%2BsjrPJUqU-JvYKETLBxuhqgbPjw%40mail.g...
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Assert in test_bms_membership();
2026-09-08 11:52 Assert in test_bms_membership(); Ilya Cherdakov <i.cherdakov.pg@gmail.com>
2026-09-08 13:14 ` Re: Assert in test_bms_membership(); Andres Freund <andres@anarazel.de>
2026-09-08 19:32 ` Re: Assert in test_bms_membership(); Zsolt Parragi <zsolt.parragi@percona.com>
@ 2026-09-08 20:09 ` Andres Freund <andres@anarazel.de>
2026-09-08 22:55 ` Re: Assert in test_bms_membership(); Michael Paquier <michael@paquier.xyz>
0 siblings, 1 reply; 5+ messages in thread
From: Andres Freund @ 2026-09-08 20:09 UTC (permalink / raw)
To: Zsolt Parragi <zsolt.parragi@percona.com>; +Cc: pgsql-hackers@lists.postgresql.org, Ilya Cherdakov <i.cherdakov.pg@gmail.com>
Hi,
On 2026-09-08 14:32:31 -0500, Zsolt Parragi wrote:
> This seem to be 0002 from a patchset I submitted yesterday[1].
>
> > Perhaps a stupid question, but: Who cares?
>
> My reasoning for this was that the other test module that has the same
> issue (test_extensible) states that it is an example for extension
> developers:
>
> This module can be used as a template for developers willing to develop
> their own extensions. "Writing a Custom Scan Provider" covers the
> documentation for custom scans.
> So I thought a small fix is a good improvement there, and then
> test_bms_membership was an easy follow up because it's the same thing.
We are drowning in patches, with actual (not AI) review and committer
bandwidth being the bottleneck. I think showing that we accept patches for
making test modules not crash when held in bogus ways is a good way to make
that even worse.
I think using these modules as templates for real extensions tends to be a not
great idea. I turns out test code, which tends to lean towards testing edge
cases etc, is rarely nice, easy to understand, code.
Greetings,
Andres Freund
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Assert in test_bms_membership();
2026-09-08 11:52 Assert in test_bms_membership(); Ilya Cherdakov <i.cherdakov.pg@gmail.com>
2026-09-08 13:14 ` Re: Assert in test_bms_membership(); Andres Freund <andres@anarazel.de>
2026-09-08 19:32 ` Re: Assert in test_bms_membership(); Zsolt Parragi <zsolt.parragi@percona.com>
2026-09-08 20:09 ` Re: Assert in test_bms_membership(); Andres Freund <andres@anarazel.de>
@ 2026-09-08 22:55 ` Michael Paquier <michael@paquier.xyz>
0 siblings, 0 replies; 5+ messages in thread
From: Michael Paquier @ 2026-09-08 22:55 UTC (permalink / raw)
To: Andres Freund <andres@anarazel.de>; +Cc: Zsolt Parragi <zsolt.parragi@percona.com>; pgsql-hackers@lists.postgresql.org, Ilya Cherdakov <i.cherdakov.pg@gmail.com>
On Tue, Sep 08, 2026 at 04:09:27PM -0400, Andres Freund wrote:
> We are drowning in patches, with actual (not AI) review and committer
> bandwidth being the bottleneck. I think showing that we accept patches for
> making test modules not crash when held in bogus ways is a good way to make
> that even worse.
With or without AI, drowning in patches for the past 8 years 4 months
has just been a part of my life. If somebody takes the time to send a
patch, I'll look at it. And here, FWIW, I don't mind much.
> I think using these modules as templates for real extensions tends to be a not
> great idea. I turns out test code, which tends to lean towards testing edge
> cases etc, is rarely nice, easy to understand, code.
Depends, I guess.
Note: the other thread has a patch, let's keep things there.
--
Michael
Attachments:
signature.asc (application/pgp-signature, 832B) download
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2026-09-08 22:55 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-09-08 11:52 Assert in test_bms_membership(); Ilya Cherdakov <i.cherdakov.pg@gmail.com>
2026-09-08 13:14 ` Andres Freund <andres@anarazel.de>
2026-09-08 19:32 ` Zsolt Parragi <zsolt.parragi@percona.com>
2026-09-08 20:09 ` Andres Freund <andres@anarazel.de>
2026-09-08 22:55 ` Michael Paquier <michael@paquier.xyz>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox