Re: [PATCH] bms_prev_member() can read beyond the end of the array of allocated words

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Greg Burd <greg(at)burd(dot)me>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [PATCH] bms_prev_member() can read beyond the end of the array of allocated words
Date: 2025-08-14 23:06:33
Message-ID: CAApHDvpHpogxAK+2BM3b4VBKGq09nabLq+GqzS1-M_B5sHrtCg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, 15 Aug 2025 at 07:45, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Anyway, that's off-topic for the present thread. I believe it's
> middle-of-the-night in Rowley's time zone, so I was waiting for
> further comment from him before taking any action.

The v5 patch looks good to me.

FWIW, after sleeping, I'm now very much against using < rather than <=
for the Assert. The reason being that it makes it impossible to build
bms_prev_member() loops with a dynamic start point. Right now we
document that we expect the loop to be started with -1, but if someone
wants to start at some arbitrary point in the set, then they need to
be able to pass some_member + 1. If some_member happens to be the
highest bit in the last word then your Assert will fail for no good
reason.

I'm happy to push Greg's v5 patch if you have no counterarguments.

David

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Masahiko Sawada 2025-08-14 23:07:54 Re: POC: enable logical decoding when wal_level = 'replica' without a server restart
Previous Message Peter Geoghegan 2025-08-14 23:05:02 Re: index prefetching