-
Notifications
You must be signed in to change notification settings - Fork 127
Open
Description
Progress
- Fix unsoundness in
FromBytes::read_from_io - Update documentation as described below
These days, MaybeUninit::zeroed is pretty clear that you cannot expect all padding bytes to be zero in the output value (same for mem::zeroed). Zerocopy mentions this, but it doesn't seem fully internalized by the library:
FromZeros::zerocontradicts this, stating that it's similar to*self = Self::new_zeroed()and that the difference is it doesn't semantically drop anything. This isn't the only difference!zerois capable of fully zeroing all of the bytes of an object until it is moved into, while*self = Self::new_zeroed()doesn't guarantee you can then soundly access as a byte slice unless thatSelf: IntoBytes.FromZeros::new_zeroeddoesn't mention the same caveat asMaybeUninit::zeroedat all even though it applies.- The current implementation of
FromBytes::read_from_iois unsound, since there may still be padding bytes for!IntoBytestypes fromnew_zeroed. It should be constructing aMaybeUninit::uninit()then zeroing its bytes before casting to&mut [u8].
I'll send a PR fixing the unsoundness issue. I'm also interested in improving the documentation to be more consistent and to provide clear working alternatives to documented unsound operations.
Metadata
Metadata
Assignees
Labels
No labels