Skip to content

There is unsound unsafe code in arena-rs #1

@A1-Triard

Description

@A1-Triard
  1. The following code in arena-rs is unsound, because there is no guarantee, that zero-initialized data is a properly initialized T and dereferencing non-properly initialized data is an undefined behavior:

    unsafe {
        *ptr = value;
        // ...
    }

    The *ptr = value line should be replaced with std::ptr::write(ptr, value).

  2. There is no guarantee that T object is properly aligned and thus there is an another undefined behavior because only a pointer to a properly aligned object can be dereferenced without undefined behavior.

    Arena should use std::mem::align_of to obtain information about T alignment, and insert appropriate padding before T.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions