Skip to content

Unsound transmute in safe method #274

@shinmao

Description

@shinmao

pub fn as_object_id(&self) -> &ObjectId {
unsafe { std::mem::transmute::<&ChunkId, &ObjectId>(&self) }
}

The safe method as_object_id used transmute to convert &ChunkId to &ObjectId. When we use transmute on reference, we need to ensure the layout (e.g., size and alignment) by ourselves. Even though ChunkId and ObjectId have the same type definition, rust compiler preserves the right to reorder and add padding bytes to the struct of repr(Rust) representation. Suggest to add repr(C) to both struct to make this guarantee.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions