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

Undefined Behavior when T contains uninit bytes #3

Closed
TyPR124 opened this issue Feb 7, 2020 · 2 comments · Fixed by #6
Closed

Undefined Behavior when T contains uninit bytes #3

TyPR124 opened this issue Feb 7, 2020 · 2 comments · Fixed by #6

Comments

@TyPR124
Copy link
Contributor

TyPR124 commented Feb 7, 2020

Example: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=d75fb532da27fbb22467a2b3b9439119

Use Tools -> Miri, it detects undefined behavior in Stowaway::new.

@TyPR124
Copy link
Contributor Author

TyPR124 commented Feb 7, 2020

It appears that unconditionally using MaybeUninit::zeroed() in Stowaway::new() is enough to fix this.

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=1a880674c2154bc3e70aef1bf4ae5d36

@Lucretiel
Copy link
Owner

Ah, yes, I was a bit worried about this. I guess those bytes are allowed to be uninit even though they're still "read" whenever the structure is copied, because they're never "used".

RustyYato added a commit to RustyYato/stowaway that referenced this issue Apr 8, 2020
reorganize tests
remove faulty test from Lucretiel#3
RustyYato added a commit to RustyYato/stowaway that referenced this issue Apr 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants