Skip to content

Potential Undefined Behavior Reported by Miri #33

@yilin0518

Description

@yilin0518

Hi!

We are a team of researchers studying the memory safety problem in Rust. As part of our ongoing research, we performed random testing on bitmaps (version: 3.2.1) and found that the following code snippet is reported as undefined behavior by Miri:

#![feature(allocator_api)]
use bitmaps::*;
fn main() {
    let v80 = [55, 30];
    let v81 = <Bitmap::<256> as std::convert::From<[u128;2]>>::from(v80);
    let v89 = <std::arch::x86_64::__m256i as std::convert::From<Bitmap::<256>>>::from(v81);
}

Here is part of the error message:

error: Undefined Behavior: calling a function that requires unavailable target features: avx
   --> /home/chenyl/projects/Itgen_test/extra/bitmaps-3.2.1/src/bitmap.rs:699:22
    |
699 |             unsafe { data.load_m256i() }
    |                      ^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here
    |
    = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
    = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
    = note: BACKTRACE:
    = note: inside `bitmaps::bitmap::x86_arch::<impl std::convert::From<bitmaps::Bitmap<256>> for std::arch::x86_64::__m256i>::from` at /home/chenyl/projects/Itgen_test/extra/bitmaps-3.2.1/src/bitmap.rs:699:22: 699:39
note: inside `main`
   --> src/main.rs:6:15
    |
  6 | ... = <std::arch::x86_64::__m256i as std::convert::From<Bitmap::<256>>>::from(v59);
    |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

error: aborting due to 1 previous error; 1 warning emitted

You can reproduce this UB by using the following command: MIRIFLAGS="-Zmiri-ignore-leaks -Zmiri-disable-stacked-borrows" cargo +nightly-2025-09-10 miri run
I notice that there is already an issue talking about this UB, here I provide the POC you can check out.

We’d appreciate it if you could take a look and confirm whether this behavior indicates a real issue, or if it’s a false positive or an expected limitation of Miri.

Thank you very much for your time and for maintaining this great project! 🙏

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions