Skip to content
This repository has been archived by the owner on Feb 7, 2021. It is now read-only.

small uninitialized types are unsound #8

Closed
RustyYato opened this issue Apr 8, 2020 · 6 comments · Fixed by #12
Closed

small uninitialized types are unsound #8

RustyYato opened this issue Apr 8, 2020 · 6 comments · Fixed by #12

Comments

@RustyYato
Copy link
Contributor

RustyYato commented Apr 8, 2020

Similar to #3, but it can't be fixed by zeroing beforehand

struct Thing(MaybeUninit<usize>);
fn main() {
    assert_eq!(size_of::<Thing>(), size_of::<*mut Thing>());
    let thing = Thing(MaybeUninit::uninit());
    let stowed = Stowaway::new(thing); // miri fails here, encountered uninitialized bytes
}
@Lucretiel
Copy link
Owner

Can you create a PR with a test case that fails in miri so that I can investigate further and protect against future regressions?

@RustyYato
Copy link
Contributor Author

Sure

RustyYato added a commit to RustyYato/stowaway that referenced this issue Apr 8, 2020
RustyYato added a commit to RustyYato/stowaway that referenced this issue Apr 8, 2020
RustyYato added a commit to RustyYato/stowaway that referenced this issue Apr 10, 2020
Lucretiel added a commit that referenced this issue Apr 12, 2020
@Lucretiel
Copy link
Owner

FWIW, it appears that the issue isn't that MIRI doesn't copy the uninitialized bytes, but that it doesn't consider filling a uninitialized int with them as UB until the int is "used" in some way. However, this is considered a bug in MIRI (rust-lang/miri#1340), so the unsoundness is still unsound. I'll be publishing a PR later today and I'd love if you could review it.

@RustyYato
Copy link
Contributor Author

Cool, I wasn't aware of that! Thanks for the link.

@Lucretiel
Copy link
Owner

There's also a lot of good discussion in the answer & comments of the stackoverflow question I posted on this topic, especially related to the current progress in defining the soundness rules for this sort of thing.

@Lucretiel
Copy link
Owner

Published 2.0.0

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants