From 5cfd33f5e736110b5fb681c231e92954751c3e4a Mon Sep 17 00:00:00 2001 From: nils <48135649+Nilstrieb@users.noreply.github.com> Date: Fri, 27 May 2022 13:30:48 +0200 Subject: [PATCH] Fix `metrics::Cow` provenance issue (#303) --- metrics/src/cow.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/metrics/src/cow.rs b/metrics/src/cow.rs index 5ff200b5..88d9b70c 100644 --- a/metrics/src/cow.rs +++ b/metrics/src/cow.rs @@ -330,7 +330,9 @@ unsafe impl Cowable for str { #[inline] fn owned_into_parts(owned: String) -> (NonNull, Metadata) { - let mut owned = ManuallyDrop::new(owned); + // We need to go through Vec here to get provenance for the entire allocation + // instead of just the initialized parts. + let mut owned = ManuallyDrop::new(owned.into_bytes()); let ptr = unsafe { NonNull::new_unchecked(owned.as_mut_ptr()) }; let metadata = Metadata::from_owned(owned.len(), owned.capacity()); (ptr, metadata)