Re: [PATCH] bms_prev_member() can read beyond the end of the array of allocated words - Mailing list pgsql-hackers

From David Rowley
Subject Re: [PATCH] bms_prev_member() can read beyond the end of the array of allocated words
Date
Msg-id CAApHDvqRFbGZx_7FZ-VjVj8m6XzX_Hzmz=FbOvO6fGhNx0EggQ@mail.gmail.com
Whole thread Raw
In response to Re: [PATCH] bms_prev_member() can read beyond the end of the array of allocated words  (Greg Burd <greg@burd.me>)
Responses Re: [PATCH] bms_prev_member() can read beyond the end of the array of allocated words
List pgsql-hackers
On Fri, 15 Aug 2025 at 02:21, Greg Burd <greg@burd.me> wrote:
> I found this too, and also the "one above" part seemed wrong to me as well.

It is valid to pass prevbit as a->nwords * BITS_PER_BITMAPWORD as the
code does "prevbit--;". Maybe it would be less confusing if it were
written as:

 * "prevbit" must be less than or equal to "a->nwords * BITS_PER_BITMAPWORD".

The Assert should be using <= rather than <.

David



pgsql-hackers by date:

Previous
From: Alexander Borisov
Date:
Subject: Re: Improve the performance of Unicode Normalization Forms.
Next
From: KAZAR Ayoub
Date:
Subject: Re: Speed up COPY FROM text/CSV parsing using SIMD