mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-23 13:41:32 +00:00
Validate descriptor max on creating new table or memory (#186)
This commit is contained in:
@ -266,6 +266,7 @@ impl std::fmt::Display for CallError {
|
|||||||
pub enum CreationError {
|
pub enum CreationError {
|
||||||
UnableToCreateMemory,
|
UnableToCreateMemory,
|
||||||
UnableToCreateTable,
|
UnableToCreateTable,
|
||||||
|
InvalidDescriptor(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq for CreationError {
|
impl PartialEq for CreationError {
|
||||||
@ -279,6 +280,11 @@ impl std::fmt::Display for CreationError {
|
|||||||
match self {
|
match self {
|
||||||
CreationError::UnableToCreateMemory => write!(f, "Unable to Create Memory"),
|
CreationError::UnableToCreateMemory => write!(f, "Unable to Create Memory"),
|
||||||
CreationError::UnableToCreateTable => write!(f, "Unable to Create Table"),
|
CreationError::UnableToCreateTable => write!(f, "Unable to Create Table"),
|
||||||
|
CreationError::InvalidDescriptor(msg) => write!(
|
||||||
|
f,
|
||||||
|
"Unable to create because the supplied descriptor is invalid: \"{}\"",
|
||||||
|
msg
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,15 @@ impl Memory {
|
|||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn new(desc: MemoryDescriptor) -> Result<Self, CreationError> {
|
pub fn new(desc: MemoryDescriptor) -> Result<Self, CreationError> {
|
||||||
|
if let Some(max) = desc.maximum {
|
||||||
|
if max < desc.minimum {
|
||||||
|
return Err(CreationError::InvalidDescriptor(
|
||||||
|
"Max number of memory pages is less than the minimum number of pages"
|
||||||
|
.to_string(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let variant = if !desc.shared {
|
let variant = if !desc.shared {
|
||||||
MemoryVariant::Unshared(UnsharedMemory::new(desc)?)
|
MemoryVariant::Unshared(UnsharedMemory::new(desc)?)
|
||||||
} else {
|
} else {
|
||||||
|
@ -50,6 +50,14 @@ impl Table {
|
|||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn new(desc: TableDescriptor) -> Result<Self, CreationError> {
|
pub fn new(desc: TableDescriptor) -> Result<Self, CreationError> {
|
||||||
|
if let Some(max) = desc.maximum {
|
||||||
|
if max < desc.minimum {
|
||||||
|
return Err(CreationError::InvalidDescriptor(
|
||||||
|
"Max table size is less than the minimum size".to_string(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mut local = vm::LocalTable {
|
let mut local = vm::LocalTable {
|
||||||
base: ptr::null_mut(),
|
base: ptr::null_mut(),
|
||||||
count: 0,
|
count: 0,
|
||||||
|
Reference in New Issue
Block a user