Skip to content

derive(IntoBytes) accepts DSTs with trailing padding #3063

@jswrenn

Description

@jswrenn

derive(IntoBytes) erroneously accepts repr(C, align(X)) DSTs with dynamic trailing padding; e.g.

#[derive(IntoBytes)]
#[repr(C, align(4))]
struct Unsound([u8]);

The derive accepts this because it merely confirms that [u8] is Unaligned, whereas it should be failing on the align directive. The sized analysis codepath correctly takes this into account; e.g.:

#[derive(IntoBytes)] // Compile error!
#[repr(C, align(4))]
struct Sized([u8; 3]);

Bug confirmed on v0.8.39 (latest release at time of reporting), but likely present on earlier releases. Looks like this slipped in with #2679, and was probably missed because the testing infra borrowed for the sized case also doesn't reason about outer align directives.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions