You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For zerocopy, @joshlf and I are interested in whether we can soundly round-trip values through a union that aren't bit-valid instances of a non-ZST field; e.g.:
unionTricky{a:bool,b:(),}fnmain(){let src = 3u8;// Is it sound to do this? Or insta-UB a la transmuting `3` to `bool`?let dst:Tricky = unsafe{
core::mem::transmute(src)};// Is it sound to do this? Or are we possibly reading an uninit byte here?assert_eq!(src,unsafe{ core::mem::transmute(dst)})}
The reasons for our concern is that we know typed copies don't have to preserve padding, but will they preserve initialized-but-invalid bytes?
The text was updated successfully, but these errors were encountered:
RalfJung
changed the title
Do typed copies preserve invalid bytes?
Do typed copies of unions preserve invalid bytes?
Feb 8, 2025
RalfJung
changed the title
Do typed copies of unions preserve invalid bytes?
Do typed copies of unions preserve "invalid" bytes?
Feb 8, 2025
This is tied up with the broader discussion around the value representation of unions, #438 and #494.
I think for unions that look like MaybeUninit, we have general consensus that non-padding bytes are exactly preserved -- but we don't have stable guarantees in that area and we don't (yet) have a good framework for even making such guarantees.
For zerocopy, @joshlf and I are interested in whether we can soundly round-trip values through a union that aren't bit-valid instances of a non-ZST field; e.g.:
The reasons for our concern is that we know typed copies don't have to preserve padding, but will they preserve initialized-but-invalid bytes?
The text was updated successfully, but these errors were encountered: