mirror of
https://github.com/fluencelabs/wasmer
synced 2025-05-18 21:21:19 +00:00
Merge #673
673: Add memory descriptor validation r=bjfish a=bjfish Fixes #653 Co-authored-by: Brandon Fish <brandon.j.fish@gmail.com>
This commit is contained in:
commit
d12ea66f90
@ -73,6 +73,12 @@ impl Memory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if desc.shared && desc.maximum.is_none() {
|
||||||
|
return Err(CreationError::InvalidDescriptor(
|
||||||
|
"Max number of pages is required for shared memory".to_string(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
let variant = if !desc.shared {
|
let variant = if !desc.shared {
|
||||||
MemoryVariant::Unshared(UnsharedMemory::new(desc)?)
|
MemoryVariant::Unshared(UnsharedMemory::new(desc)?)
|
||||||
} else {
|
} else {
|
||||||
@ -325,4 +331,17 @@ mod memory_tests {
|
|||||||
assert_eq!(unshared_memory.size(), Pages(10));
|
assert_eq!(unshared_memory.size(), Pages(10));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_invalid_descriptor_returns_error() {
|
||||||
|
let result = Memory::new(MemoryDescriptor {
|
||||||
|
minimum: Pages(10),
|
||||||
|
maximum: None,
|
||||||
|
shared: true,
|
||||||
|
});
|
||||||
|
assert!(
|
||||||
|
result.is_err(),
|
||||||
|
"Max number of pages is required for shared memory"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user