Skip to content

Defend against padding instability #1648

Closed
@jswrenn

Description

@jswrenn

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>()]
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions