-
Notifications
You must be signed in to change notification settings - Fork 107
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
Transmuting &mut MaybeUninit::zeroed()
to &mut [u8]
is unsound
#2319
Comments
MaybeUninit::zeroed()
to &mut [u8]
is unsound&mut MaybeUninit::zeroed()
to &mut [u8]
is unsound
kupiakos
added a commit
to kupiakos/zerocopy
that referenced
this issue
Feb 7, 2025
kupiakos
added a commit
to kupiakos/zerocopy
that referenced
this issue
Feb 7, 2025
kupiakos
added a commit
to kupiakos/zerocopy
that referenced
this issue
Feb 7, 2025
kupiakos
added a commit
to kupiakos/zerocopy
that referenced
this issue
Feb 7, 2025
See google#2319. Backport of google#2320.
kupiakos
added a commit
to kupiakos/zerocopy
that referenced
this issue
Feb 7, 2025
See google#2319. Backport of google#2320.
kupiakos
added a commit
to kupiakos/zerocopy
that referenced
this issue
Feb 7, 2025
kupiakos
added a commit
to kupiakos/zerocopy
that referenced
this issue
Feb 8, 2025
See google#2319. Includes a Miri test confirming the previous unsoundness.
kupiakos
added a commit
to kupiakos/zerocopy
that referenced
this issue
Feb 8, 2025
See google#2319. Backport of google#2320. Includes a Miri test confirming the previous unsoundness.
kupiakos
added a commit
to kupiakos/zerocopy
that referenced
this issue
Feb 8, 2025
See google#2319. Backport of google#2320. Includes a Miri test confirming the previous unsoundness.
kupiakos
added a commit
to kupiakos/zerocopy
that referenced
this issue
Feb 8, 2025
See google#2319. Includes a Miri test confirming the previous unsoundness.
kupiakos
added a commit
to kupiakos/zerocopy
that referenced
this issue
Feb 17, 2025
See google#2319. Includes a Miri test confirming the previous unsoundness.
joshlf
pushed a commit
to kupiakos/zerocopy
that referenced
this issue
Feb 19, 2025
See google#2319. Includes a Miri test confirming the previous unsoundness. gherrit-pr-id: Iede94c196c710c74d970c93935f1539e07446e50
joshlf
pushed a commit
to kupiakos/zerocopy
that referenced
this issue
Feb 19, 2025
See google#2319. Includes a Miri test confirming the previous unsoundness. gherrit-pr-id: Iede94c196c710c74d970c93935f1539e07446e50
google-pr-creation-bot
pushed a commit
to google-pr-creation-bot/zerocopy
that referenced
this issue
Feb 19, 2025
See google#2319. Includes a Miri test confirming the previous unsoundness. gherrit-pr-id: Iede94c196c710c74d970c93935f1539e07446e50
github-merge-queue bot
pushed a commit
that referenced
this issue
Feb 19, 2025
See #2319. Includes a Miri test confirming the previous unsoundness. gherrit-pr-id: Iede94c196c710c74d970c93935f1539e07446e50
github-merge-queue bot
pushed a commit
that referenced
this issue
Feb 19, 2025
See #2319. Includes a Miri test confirming the previous unsoundness. gherrit-pr-id: Iede94c196c710c74d970c93935f1539e07446e50 Co-authored-by: Alyssa Haroldsen <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Progress
FromBytes::read_from_io
These days,
MaybeUninit::zeroed
is pretty clear that you cannot expect all padding bytes to be zero in the output value (same formem::zeroed
). Zerocopy mentions this, but it doesn't seem fully internalized by the library:FromZeros::zero
contradicts 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!zero
is 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_zeroed
doesn't mention the same caveat asMaybeUninit::zeroed
at all even though it applies.FromBytes::read_from_io
is unsound, since there may still be padding bytes for!IntoBytes
types 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.
The text was updated successfully, but these errors were encountered: