Skip to content

Unsound implementation in load_prefix<T> and save_prefix<T> #2

@shinmao

Description

@shinmao

runes/src/utils.rs

Lines 71 to 75 in fd12a0a

match reader.read(unsafe {
from_raw_parts_mut(transmute::<*mut T, *mut u8>(obj as *mut T), len)
}) {
Some(x) => x == len,
None => false,

Hi, I consider that load_prefix and save_prefix could have unsound implementation. At line 72, users could transmute arbitrary types to byte slice. However, if the types contains padding bytes, consider it as u8 could lead to undefined behavior. Based on the safety part in doc, callers are required to make sure the data points to initialized values while the function here didn't guarantee the safety.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions