diff --git a/src/lib.rs b/src/lib.rs index 44818e67..d0eb1461 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -248,7 +248,7 @@ mod known_key; pub use known_key::{Error as KnownKeyError, KnownKey}; pub use crate::tape::{Node, Tape}; -use std::alloc::{alloc_zeroed, handle_alloc_error, Layout}; +use std::alloc::{alloc, handle_alloc_error, Layout}; use std::ops::{Deref, DerefMut}; use std::ptr::NonNull; @@ -490,6 +490,14 @@ impl<'de> Deserializer<'de> { // ensure we have a 0 to terminate the buffer std::ptr::write(input_buffer.as_mut_ptr().add(len), 0); + // initialize all remaingin bytes + if len < input_buffer.capacity() { + for i in len..input_buffer.capacity() { + std::ptr::write(input_buffer.as_mut_ptr().add(i), 0); + } + } + + // safety: all bytes are initialized input_buffer.set_len(input_buffer.capacity()); }; @@ -710,7 +718,7 @@ impl AlignedBuf { if mem::size_of::() < 8 && capacity > isize::MAX as usize { Self::capacity_overflow() } - let inner = match unsafe { NonNull::new(alloc_zeroed(layout)) } { + let inner = match unsafe { NonNull::new(alloc(layout)) } { Some(ptr) => ptr, None => handle_alloc_error(layout), };