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

Fix into_owned String not having enough provenance #47

Merged
merged 2 commits into from
May 27, 2022
Merged

Fix into_owned String not having enough provenance #47

merged 2 commits into from
May 27, 2022

Conversation

Nilstrieb
Copy link
Contributor

Calling .as_mut_ptr on a String actually goes through &mut str, which shrinks the provenance of the pointer to only contain the initialized bytes. This caused issues when a reconstructed String tried to write to the uninitialized part of it. The fix is to go through Vec::<u8>::as_mut_ptr, which gives provenance for the entire allocation.

Calling `.as_mut_ptr` on a `String` actually goes through `&mut str`,
which shrinks the provenance of the pointer to only contain the
initialized bytes. This caused issues when a reconstructed `String`
tried to write to the uninitialized part of it. The fix is to go through
`Vec::<u8>::as_mut_ptr`, which gives provenance for the entire
allocation.
@maciejhirsz
Copy link
Owner

Cheers!

@maciejhirsz maciejhirsz merged commit 6bb5597 into maciejhirsz:master May 27, 2022
@Nilstrieb Nilstrieb deleted the fix-provenance-out-of-bounds-write branch May 27, 2022 11:21
@CAD97
Copy link

CAD97 commented May 27, 2022

Maybe this is worth adding the method to String to keep full provenance, the way Vec does (rather than relying on the slice method)?

@Nilstrieb
Copy link
Contributor Author

I think that's a good idea. I will open a PR over the weekend.

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

Successfully merging this pull request may close these issues.

None yet

3 participants