Skip to content

Commit 97a0392

Browse files
5225225Licenser
authored andcommitted
Fix unchecked indexing in from_slice_with_buffers
1 parent 1368ee9 commit 97a0392

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/lib.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -482,11 +482,14 @@ impl<'de> Deserializer<'de> {
482482
}
483483

484484
unsafe {
485-
input_buffer
486-
.as_mut_slice()
487-
.get_kinda_unchecked_mut(..len)
488-
.clone_from_slice(input);
489-
*(input_buffer.get_kinda_unchecked_mut(len)) = 0;
485+
std::ptr::copy_nonoverlapping(
486+
input.as_ptr(),
487+
input_buffer.as_mut_ptr(),
488+
len,
489+
);
490+
491+
input_buffer.as_mut_ptr().add(len).write(0);
492+
490493
input_buffer.set_len(len);
491494
};
492495

@@ -720,15 +723,16 @@ impl AlignedBuf {
720723
}
721724
}
722725

726+
fn as_mut_ptr(&mut self) -> *mut u8 {
727+
self.inner.as_ptr()
728+
}
729+
723730
fn capacity_overflow() -> ! {
724731
panic!("capacity overflow");
725732
}
726733
fn capacity(&self) -> usize {
727734
self.capacity
728735
}
729-
fn as_mut_slice(&mut self) -> &mut [u8] {
730-
unsafe { std::slice::from_raw_parts_mut(self.inner.as_ptr(), self.len) }
731-
}
732736
unsafe fn set_len(&mut self, n: usize) {
733737
assert!(
734738
n <= self.capacity,

0 commit comments

Comments
 (0)