Skip to content

Commit

Permalink
Add memory validation
Browse files Browse the repository at this point in the history
  • Loading branch information
bjfish committed Aug 13, 2019
1 parent 5239cdb commit de8fe32
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/runtime-core/src/memory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
MemoryVariant::Unshared(UnsharedMemory::new(desc)?)
} else {
Expand Down Expand Up @@ -325,4 +331,17 @@ mod memory_tests {
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"
)
}

}

0 comments on commit de8fe32

Please sign in to comment.