pgsql: Add Asserts to validate prevbit values in bms_prev_member

From: David Rowley <drowley(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Add Asserts to validate prevbit values in bms_prev_member
Date: 2025-08-15 04:33:36
Message-ID: E1umm8G-000cy8-13@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Add Asserts to validate prevbit values in bms_prev_member

bms_prev_member() could attempt to access memory outside of the words[]
array in cases where the prevbit was a number < -1 or > a->nwords *
BITS_PER_BITMAPWORD + 1.

Here we add the Asserts to help draw attention to bogus callers so we're
more likely to catch them during development.

In passing, fix wording of bms_prev_member's header comment which talks
about how we expect the callers to ensure only valid prevbit values are
used.

Author: Greg Burd <greg(at)burd(dot)me>
Reviewed-by: David Rowley <dgrowleyml(at)gmail(dot)com>
Reviewed-by: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Discussion: https://postgr.es/m/2000A717-1FFE-4031-827B-9330FB2E9065%40getmailspring.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/b4632883d44eae892e28dafbf674e6ac3dfd824d

Modified Files
--------------
src/backend/nodes/bitmapset.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

Browse pgsql-committers by date

  From Date Subject
Next Message David Rowley 2025-08-15 05:24:11 pgsql: Fix failing -D HASH_STATISTICS builds
Previous Message Michael Paquier 2025-08-15 03:32:07 pgsql: Add SQL test for TOAST value allocations on rewrite