Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is unsound unsafe code in arena-rs #1

Open
A1-Triard opened this issue Aug 14, 2020 · 0 comments
Open

There is unsound unsafe code in arena-rs #1

A1-Triard opened this issue Aug 14, 2020 · 0 comments
Labels
bug Something isn't working

Comments

@A1-Triard
Copy link

A1-Triard commented Aug 14, 2020

  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.

@A1-Triard A1-Triard changed the title There is unsound unsafe code in arean-rs There is unsound unsafe code in arena-rs Aug 14, 2020
@BrandonDyer64 BrandonDyer64 added the bug Something isn't working label Aug 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants