mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-06 20:58:28 +00:00
Last changes to enforce size check on ther caller of memory_data_init and not the function itself
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user