Re: [PATCH v7 02/10] rust: bitmap: restrict bitmap length to at most i32::MAX
From: Burak Emir
Date: Mon Aug 17 2026 - 15:51:44 EST
On Mon, Aug 17, 2026 at 9:04 AM Eliot Courtney <ecourtney@xxxxxxxxxx> 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/DKG0U8RLO7LZ.2I1AIH0S38PAP@xxxxxxxxxx
> Reviewed-by: Yury Norov <ynorov@xxxxxxxxxx>
Reviewed-by: Burak Emir <burak.emir@xxxxxxxxx>
> Signed-off-by: Eliot Courtney <ecourtney@xxxxxxxxxx>
> ---