Serialize and deserialize structs safely
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 1.8k
- Forks
- 113
- PR merge metrics
- No merged PRs in 30d
Description
There are a few places where we unnecessarily use unsafe blocks to serialize and deserialize structs:
In particular see https://github.com/oreboot/oreboot/blob/main/src/lib/uefi/src/lib.rs. For example:
let fveh: efi::EFI_FIRMWARE_VOLUME_EXT_HEADER =
unsafe { core::ptr::read(fveh_bytes.as_ptr() as *const _) };
Instead, we should be using some Rust macros to achieve this safely. There are a number of crates built for this task:
- https://serde.rs/ is obviously the most popular. Some of its flexibility gets in the way. We just need to be able to serialize/deserialize a struct in the same format as a packed C struct.
- https://github.com/xoac/endian_codec
- https://crates.io/crates/packed_struct
- ... (I have no strong opinions for a particular crate at the moment)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/lib/uefi/src/lib.rs, especially the EFI_FIRMWARE_VOLUME_EXT_HEADER conversion shown in the issue, then locate the other unsafe struct serialization and deserialization sites. Compare the listed Rust crates for packed C-struct compatibility and determine the required byte layout and endianness. Done means the applicable conversions no longer use unsafe pointer reads while preserving the existing struct format.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- operating-systems
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100