This snippet fails due to undefined behavior when run under miri:
use stackblur_iter::imgref::ImgRefMut;
fn main() {
let mut buf = vec![
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
];
let mut img_ref = ImgRefMut::new(&mut buf, 3, 3);
stackblur_iter::blur_argb(&mut img_ref, 1);
}
stackblur-iter = "0.1.5"
rustc --version
: rustc 1.64.0-nightly (f8588549c 2022-07-18)
Error:
$ cargo miri run
Finished dev [unoptimized + debuginfo] target(s) in 0.13s
Running `/Users/marko/.rustup/toolchains/nightly-x86_64-apple-darwin/bin/cargo-miri /Users/marko/.target-cargo/miri/x86_64-apple-darwin/debug/test-stackblur`
error: Undefined Behavior: trying to reborrow from <3782> for SharedReadOnly permission at alloc1660[0x0], but that tag does not exist in the borrow stack for this location
--> /Users/marko/.cargo/registry/src/github.com-1ecc6299db9ec823/imgref-iter-0.3.3/src/iter/windows/ptr.rs:135:13
|
135 | let len = (*self.0).len();
| ^^^^^^^^^^^^^^^
| |
| trying to reborrow from <3782> for SharedReadOnly permission at alloc1660[0x0], but that tag does not exist in the borrow stack for this location
| this error occurs as part of a reborrow at alloc1660[0x0..0xc]
|
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <3782> was created by a retag at offsets [0x0..0x90]
--> src/main.rs:11:5
|
11 | stackblur_iter::blur_argb(&mut img_ref, 1);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: <3782> was later invalidated at offsets [0x8..0xc]
--> src/main.rs:11:5
|
11 | stackblur_iter::blur_argb(&mut img_ref, 1);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: backtrace:
= note: inside `imgref_iter::iter::windows::ptr::IterWindowsPtr::<u32>::window` at /Users/marko/.cargo/registry/src/github.com-1ecc6299db9ec823/imgref-iter-0.3.3/src/iter/windows/ptr.rs:135:13
= note: inside closure at /Users/marko/.cargo/registry/src/github.com-1ecc6299db9ec823/imgref-iter-0.3.3/src/iter/windows/ptr.rs:145:51
= note: inside `std::option::Option::<usize>::map::<imgref_iter::iter::generic::ptr::IterPtr<u32>, [closure@<imgref_iter::iter::windows::ptr::IterWindowsPtr<u32> as std::iter::Iterator>::next::{closure#0}]>` at /Users/marko/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/option.rs:929:29
= note: inside `<imgref_iter::iter::windows::ptr::IterWindowsPtr<u32> as std::iter::Iterator>::next` at /Users/marko/.cargo/registry/src/github.com-1ecc6299db9ec823/imgref-iter-0.3.3/src/iter/windows/ptr.rs:145:3
= note: inside `<imgref_iter::iter::windows::IterWindows<u32> as std::iter::Iterator>::next` at /Users/marko/.cargo/registry/src/github.com-1ecc6299db9ec823/imgref-iter-0.3.3/src/iter/windows/mod.rs:43:3
= note: inside `<std::iter::Zip<imgref_iter::iter::windows::ptr::IterWindowsPtrMut<u32>, imgref_iter::iter::windows::IterWindows<u32>> as std::iter::adapters::zip::ZipImpl<imgref_iter::iter::windows::ptr::IterWindowsPtrMut<u32>, imgref_iter::iter::windows::IterWindows<u32>>>::next` at /Users/marko/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/iter/adapters/zip.rs:155:21
= note: inside `<std::iter::Zip<imgref_iter::iter::windows::ptr::IterWindowsPtrMut<u32>, imgref_iter::iter::windows::IterWindows<u32>> as std::iter::Iterator>::next` at /Users/marko/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/iter/adapters/zip.rs:84:9
= note: inside `<for<'r> fn(&'r mut std::iter::Zip<imgref_iter::iter::windows::ptr::IterWindowsPtrMut<u32>, imgref_iter::iter::windows::IterWindows<u32>>) -> std::option::Option<<std::iter::Zip<imgref_iter::iter::windows::ptr::IterWindowsPtrMut<u32>, imgref_iter::iter::windows::IterWindows<u32>> as std::iter::Iterator>::Item> {<std::iter::Zip<imgref_iter::iter::windows::ptr::IterWindowsPtrMut<u32>, imgref_iter::iter::windows::IterWindows<u32>> as std::iter::Iterator>::next} as std::ops::FnOnce<(&mut std::iter::Zip<imgref_iter::iter::windows::ptr::IterWindowsPtrMut<u32>, imgref_iter::iter::windows::IterWindows<u32>>,)>>::call_once - shim(for<'r> fn(&'r mut std::iter::Zip<imgref_iter::iter::windows::ptr::IterWindowsPtrMut<u32>, imgref_iter::iter::windows::IterWindows<u32>>) -> std::option::Option<<std::iter::Zip<imgref_iter::iter::windows::ptr::IterWindowsPtrMut<u32>, imgref_iter::iter::windows::IterWindows<u32>> as std::iter::Iterator>::Item> {<std::iter::Zip<imgref_iter::iter::windows::ptr::IterWindowsPtrMut<u32>, imgref_iter::iter::windows::IterWindows<u32>> as std::iter::Iterator>::next})` at /Users/marko/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:248:5
= note: inside `std::iter::adapters::chain::and_then_or_clear::<std::iter::Zip<imgref_iter::iter::windows::ptr::IterWindowsPtrMut<u32>, imgref_iter::iter::windows::IterWindows<u32>>, (imgref_iter::iter::generic::ptr::IterPtrMut<u32>, imgref_iter::iter::generic::Iter<u32>), for<'r> fn(&'r mut std::iter::Zip<imgref_iter::iter::windows::ptr::IterWindowsPtrMut<u32>, imgref_iter::iter::windows::IterWindows<u32>>) -> std::option::Option<<std::iter::Zip<imgref_iter::iter::windows::ptr::IterWindowsPtrMut<u32>, imgref_iter::iter::windows::IterWindows<u32>> as std::iter::Iterator>::Item> {<std::iter::Zip<imgref_iter::iter::windows::ptr::IterWindowsPtrMut<u32>, imgref_iter::iter::windows::IterWindows<u32>> as std::iter::Iterator>::next}>` at /Users/marko/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/iter/adapters/chain.rs:287:13
= note: inside `<std::iter::Chain<std::iter::Zip<imgref_iter::iter::windows::ptr::IterWindowsPtrMut<u32>, imgref_iter::iter::windows::IterWindows<u32>>, std::iter::Zip<imgref_iter::iter::windows::ptr::IterWindowsPtrMut<u32>, imgref_iter::iter::windows::IterWindows<u32>>> as std::iter::Iterator>::next` at /Users/marko/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/iter/adapters/chain.rs:50:9
= note: inside `stackblur_iter::blur::<u32, stackblur_iter::color::Argb<stackblur_iter::color::serial::StackBlurrableU32>, [closure@stackblur_iter::blur_argb::{closure#0}], fn(stackblur_iter::color::Argb<stackblur_iter::color::serial::StackBlurrableU32>) -> u32 {stackblur_iter::color::Argb::<stackblur_iter::color::serial::StackBlurrableU32>::to_u32}>` at /Users/marko/.cargo/registry/src/github.com-1ecc6299db9ec823/stackblur-iter-0.1.5/src/lib.rs:88:23
= note: inside `stackblur_iter::blur_argb` at /Users/marko/.cargo/registry/src/github.com-1ecc6299db9ec823/stackblur-iter-0.1.5/src/lib.rs:233:2
note: inside `main` at src/main.rs:11:5
--> src/main.rs:11:5
|
11 | stackblur_iter::blur_argb(&mut img_ref, 1);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
error: aborting due to previous error
bug help wanted