Skip to content

Comments

Fix into_owned String not having enough provenance#47

Merged
maciejhirsz merged 2 commits intomaciejhirsz:masterfrom
Noratrieb:fix-provenance-out-of-bounds-write
May 27, 2022
Merged

Fix into_owned String not having enough provenance#47
maciejhirsz merged 2 commits intomaciejhirsz:masterfrom
Noratrieb:fix-provenance-out-of-bounds-write

Conversation

@Noratrieb
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.

Noratrieb added 2 commits May 26, 2022 22:35
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
@Noratrieb Noratrieb 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)?

@Noratrieb
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.

3 participants