Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix overflow during validation on 32-bit machines. #9

Merged
merged 1 commit into from
Oct 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion runtime/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl MemInstStore {
}
}
// Can't allocate more than 4GB since its a 32-bits machine
if sz + new > (1 << 32) / PAGE_SIZE {
if sz + new > ((1u64 << 32) / PAGE_SIZE as u64) as usize {
return None;
}
mem.data.resize((sz + new) * PAGE_SIZE, 0);
Expand Down
6 changes: 3 additions & 3 deletions runtime/src/valid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,9 @@ fn check_table(table: &ast::Table) -> Option<()> {

fn check_memory(mem: &ast::Memory) -> Option<()> {
// Can't allocate more than 4GB since its a 32-bits machine
let max = (1 << 32) / 65536;
if mem.type_.limits.min as usize > max
|| (mem.type_.limits.max.is_some() && mem.type_.limits.max.unwrap() as usize > max)
let max = (1u64 << 32) / 65536;
if mem.type_.limits.min as u64 > max
|| (mem.type_.limits.max.is_some() && mem.type_.limits.max.unwrap() as u64 > max)
{
return None;
}
Expand Down