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

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

Open
shinmao opened this issue Aug 30, 2023 · 0 comments
Open

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

shinmao opened this issue Aug 30, 2023 · 0 comments

Comments

@shinmao
Copy link

shinmao commented Aug 30, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant