-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
core::iter::repeat_n is unsound with Box<T> #130141
Comments
See also: rust-lang/unsafe-code-guidelines#245 |
The minimal example is actually this: fn main() {
let y = std::iter::repeat_n(Box::new(0), 0);
let _z = y;
} Because let mut x = ManuallyDrop::new(Box::new(0));
ManuallyDrop::drop(&mut x);
let _y = x; Which is indeed rust-lang/unsafe-code-guidelines#245. I quite strongly think that this is a bug in miri and/or |
WG-prioritization assigning priority (Zulip discussion). @rustbot label -I-prioritize +P-critical |
Yeah, it should -- someone just has to implement |
I tweaked the title because while there is an experimental Miri flag to make Unique magical, codegen only has special treatment for Box. |
…homcc,traviscross Document subtleties of `ManuallyDrop` After seeing rust-lang#130140 and rust-lang#130141, I figured that `ManuallyDrop` needs documentation explaining its subtleties, hence this PR. See also rust-lang/unsafe-code-guidelines#245
Rollup merge of rust-lang#130279 - theemathas:manually-drop-docs, r=thomcc,traviscross Document subtleties of `ManuallyDrop` After seeing rust-lang#130140 and rust-lang#130141, I figured that `ManuallyDrop` needs documentation explaining its subtleties, hence this PR. See also rust-lang/unsafe-code-guidelines#245
This is technically different from #130140 as there's no UAF. However, using
core::iter::repeat_n
withBox<T>
has undefined behavior if you use the last/original element after moving the iterator, since theBox
field has noalias properties.Miri Backtrace
Wrapping the element using
MaybeUninit
(orMaybeDangling
once we have that) should make this sound.The text was updated successfully, but these errors were encountered: