1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-21 23:18:13 +00:00

fix(core): unaligned array in protobuf decoder

[no changelog]
This commit is contained in:
Martin Milata 2024-10-25 01:12:55 +02:00
parent 48b9c8456f
commit eb74c1a8a5
2 changed files with 6 additions and 4 deletions

View File

@ -93,7 +93,7 @@ if not PROTOC:
PROTOC_PREFIX = Path(PROTOC).resolve().parent.parent
ENUM_ENTRY = c.PrefixedArray(c.Byte, c.Int16ul)
ENUM_ENTRY = c.PrefixedArray(c.Int16ul, c.Int16ul)
FIELD_STRUCT = c.Struct(
"tag" / c.Byte,

View File

@ -209,7 +209,7 @@ pub unsafe fn get_msg(msg_offset: u16) -> MsgDef {
unsafe fn get_enum(enum_offset: u16) -> EnumDef {
// #[repr(C, packed)]
// struct EnumDef {
// count: u8,
// count: u16,
// vals: [u16],
// }
@ -217,8 +217,10 @@ unsafe fn get_enum(enum_offset: u16) -> EnumDef {
// definition inside `ENUM_DEFS`.
unsafe {
let ptr = ENUM_DEFS.as_ptr().add(enum_offset as usize);
let count = ptr.offset(0).read() as usize;
let vals = ptr.offset(1);
let count_lo = ptr.offset(0).read();
let count_hi = ptr.offset(1).read();
let count = u16::from_le_bytes([count_lo, count_hi]) as usize;
let vals = ptr.offset(2);
EnumDef {
values: slice::from_raw_parts(vals.cast(), count),