RUSTSEC-2020-0009

read_scalar and read_scalar_at allow transmuting values without unsafe blocks

Issued
Package
flatbuffers (crates.io)
Type
Vulnerability
Aliases
Details
https://github.com/google/flatbuffers/issues/5825
Patched
  • >=2.0.0
Unaffected
  • <0.4.0
Affected Functions
Version
flatbuffers::read_scalar
  • >=0.4.0
flatbuffers::read_scalar_at
  • >=0.4.0

Description

The read_scalar and read_scalar_at functions are unsound because they allow transmuting values without unsafe blocks.

The following example shows how to create a dangling reference:

fn main() {
    #[derive(Copy, Clone, PartialEq, Debug)]
    struct S(&'static str);
    impl flatbuffers::EndianScalar for S {
        fn to_little_endian(self) -> Self { self }
        fn from_little_endian(self) -> Self { self }
    }
    println!("{:?}", flatbuffers::read_scalar::<S>(&[1; std::mem::size_of::<S>()]));
}

More