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

Maybe unsound in as_bytes #2305

Open
lwz23 opened this issue Dec 5, 2024 · 1 comment
Open

Maybe unsound in as_bytes #2305

lwz23 opened this issue Dec 5, 2024 · 1 comment

Comments

@lwz23
Copy link

lwz23 commented Dec 5, 2024

unsafe { slice::from_raw_parts(self.offset as *const u8, self.length as usize) }

pub fn as_bytes(&self) -> &[u8] {
        unsafe { slice::from_raw_parts(self.offset as *const u8, self.length as usize) }
    }

I'm not sure if this code has an unsound problem, but it calls from_raw_parts without any checks. Although memory is a private mod, I decided to report the issue because I didn't see any //SAFETY to indicate this.

@chipshort
Copy link
Collaborator

I'm pretty sure it's not unsound because the only way we create the Regions is from a Vec or from a slice which both should fulfill all the safety requirements.
But it's always a good idea to document this.

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

2 participants