You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The documentation for secrets::traits::Bytes states:
Any type that implements Bytes must not exhibit undefined behavior when its underlying bits are set to any arbitrary bit pattern.
Currently, bool and char (the primitive types) have implementations for Bytes (https://github.com/stouset/secrets/blob/master/src/traits.rs#L69 ), but these types can not be set to arbitrary bit patterns (specifically, bool must have the bit pattern 0x00 or 0x01, and char must have a bit pattern in the range 0x0000_0000..=0x0000_D7FF or the range 0x0000_E000..=0x0010_FFFF)
The following example program exhibits undefined behavior due to this (run it in debug mode and in release mode and you'll most likely see different results):
fnmain(){let b:char = secrets::traits::Bytes::uninitialized();match b {// Note that these two patterns together include all valid char values'\x00'..='\u{10fffe}' => dbg!("char1"),'\x01'..='\u{10ffff}' => dbg!("char2"),// This prints in release mode on my machine (secrets 1.2.0, rustc 1.61.0)
_ => dbg!("huh?"),// This prints in debug mode on my machine};}
The text was updated successfully, but these errors were encountered:
zachs18
added a commit
to zachs18/secrets
that referenced
this issue
May 25, 2022
The documentation for
secrets::traits::Bytes
states:Currently,
bool
andchar
(the primitive types) have implementations forBytes
(https://github.com/stouset/secrets/blob/master/src/traits.rs#L69 ), but these types can not be set to arbitrary bit patterns (specifically,bool
must have the bit pattern0x00
or0x01
, andchar
must have a bit pattern in the range0x0000_0000..=0x0000_D7FF
or the range0x0000_E000..=0x0010_FFFF
)The following example program exhibits undefined behavior due to this (run it in debug mode and in release mode and you'll most likely see different results):
The text was updated successfully, but these errors were encountered: