Skip to content
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

Defend against padding instability #1648

Closed
Tracked by #671
jswrenn opened this issue Sep 12, 2024 · 3 comments
Closed
Tracked by #671

Defend against padding instability #1648

jswrenn opened this issue Sep 12, 2024 · 3 comments

Comments

@jswrenn
Copy link
Collaborator

jswrenn commented Sep 12, 2024

In light of rust-lang/rust#129778, we should do more to defend against misconceptions about the durability of padding bytes across moves. For example, FromZeros::new_zeroed returns its value by-move, and so padding bytes within Self may not be 0.

We can do some combination of the following. First, we can aggressively sign-post this risk. As a rule, one shouldn't depend on the value of padding bytes.

Second, we can wrap zeroed types in a type that ensures padding remains preserved; e.g.:

union PaddingStable<T> {
    a: core::mem::ManuallyDrop<T>,
    b: [u8; core::mem::size_of::<u8>()]
}
@jswrenn jswrenn added the blocking-next-release This issue should be resolved before we release on crates.io label Sep 13, 2024
@joshlf joshlf mentioned this issue Sep 14, 2024
87 tasks
joshlf added a commit that referenced this issue Sep 15, 2024
Document that writes to padding bytes are not preserved when an object
is moved or copied.

Makes progress on #1648
joshlf added a commit that referenced this issue Sep 15, 2024
Document that writes to padding bytes are not preserved when an object
is moved or copied.

Makes progress on #1648
joshlf added a commit that referenced this issue Sep 15, 2024
Document that writes to padding bytes are not preserved when an object
is moved or copied.

Makes progress on #1648
@RalfJung
Copy link

union PaddingStable<T> {
    a: core::mem::ManuallyDrop<T>,
    b: [u8; core::mem::size_of::<u8>()]
}

The last u8 should be T, right?

@jswrenn
Copy link
Collaborator Author

jswrenn commented Sep 16, 2024

Yeah, that's a typo. Unfortunately, using T there also isn't currently stable. For now, the best we can do is documentation, I think (#1660).

joshlf added a commit that referenced this issue Sep 16, 2024
Document that writes to padding bytes are not preserved when an object
is moved or copied.

Makes progress on #1648
@joshlf joshlf added blocking-next-release-publicization and removed blocking-next-release This issue should be resolved before we release on crates.io labels Sep 16, 2024
github-merge-queue bot pushed a commit that referenced this issue Sep 16, 2024
Document that writes to padding bytes are not preserved when an object
is moved or copied.

Makes progress on #1648
@joshlf
Copy link
Member

joshlf commented Sep 16, 2024

If we need to add a utility type, we can do that when the need arises.

For now, I'll consider this closed by #1660.

@joshlf joshlf closed this as completed Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants