Re: [PATCH v7 02/10] rust: bitmap: restrict bitmap length to at most i32::MAX

Burak Emir <[email protected]>
Newsgroups dev.linux.lists.nova-gpu,org.freedesktop.lists.dri-devel,org.kernel.vger.linux-kernel,org.kernel.vger.rust-for-linux
Message-ID <CABwQupP-qu9S--ob82ZPDuiNH3LMwqZpjZ2LENg3hsGFGvr1Jw@mail.gmail.com>
On Mon, Aug 17, 2026 at 9:04 AM Eliot Courtney <[email protected]> wrote:
>
> It is currently possible to construct a non-`BitmapVec` backed
> `Bitmap` using `Bitmap::from_raw` that is larger than `i32::MAX`, and
> it is not part of the unsafe requirements. Restricting all bitmaps
> (even non-`BitmapVec` backed ones) to a maximum size of `i32::MAX`
> simplifies a few things and matches `BitmapVec::MAX_LEN`.
>
> Add that requirement to the unsafe requirements on `Bitmap::from_raw`
> and `Bitmap::from_raw_mut`, and to the invariants on `Bitmap`.
>
> This also fixes u32 casts truncating in `copy_and_extend`, which could
> otherwise lead to OOB writes.
>
> Fixes: 11eca92a2cae ("rust: add bitmap API.")
> Link: https://lore.kernel.org/[email protected]
> Reviewed-by: Yury Norov <[email protected]>

Reviewed-by: Burak Emir <[email protected]>

> Signed-off-by: Eliot Courtney <[email protected]>
> ---
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.