Last changes to enforce size check on ther caller of memory_data_init and not the function itself

This commit is contained in:
ptitSeb
2022-10-06 09:51:11 +02:00
parent 2fbf1f5bf1
commit 50eed71ab0
2 changed files with 10 additions and 8 deletions

View File

@@ -5,7 +5,7 @@
//!
//! `Memory` is to WebAssembly linear memories what `Table` is to WebAssembly tables.
use crate::trap::{Trap, TrapCode};
use crate::trap::Trap;
use crate::{mmap::Mmap, store::MaybeInstanceOwned, vmcontext::VMMemoryDefinition};
use more_asserts::assert_ge;
use std::cell::UnsafeCell;
@@ -399,13 +399,6 @@ pub unsafe fn initialize_memory_with_data(
start: usize,
data: &[u8],
) -> Result<(), Trap> {
if start
.checked_add(data.len())
.map_or(true, |end| end > memory.current_length)
{
return Err(Trap::lib(TrapCode::HeapAccessOutOfBounds));
}
let mem_slice = slice::from_raw_parts_mut(memory.base, memory.current_length);
let end = start + data.len();
let to_init = &mut mem_slice[start..end];
@@ -441,6 +434,9 @@ where
fn try_clone(&self) -> Option<Box<dyn LinearMemory + 'static>>;
#[doc(hidden)]
/// # Safety
/// This function is unsafe because WebAssembly specification requires that data is always set at initialization time.
/// It should be the implementors responsibility to make sure this respects the spec
unsafe fn initialize_with_data(&self, start: usize, data: &[u8]) -> Result<(), Trap> {
let memory = self.vmmemory().as_ref();