Skip to content

[Rust] impl Follow for bool is unsound #5530

@nagisa

Description

@nagisa

The implementation impl Follow for bool is defined here and ends up calling read_scalar_at::<bool>(...). read_scalar_at (defined here) is for all intents and purposes a transmute and therefore given a byte that is not exactly 0 or 1 will produce a value of bool that has an invalid underlying bit pattern. That is UB in Rust. Invoking it is as easy as

bool::follow(b"\x42", 0)

or something along the lines.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions