fix overflow

This commit is contained in:
Chris Fallin 2023-02-24 21:54:04 -08:00
parent ac2556a7ad
commit dc541497b2

View file

@ -946,7 +946,7 @@ pub fn const_eval(
(Operator::Unreachable, []) => None,
(Operator::I32Load { memory }, [ConstVal::I32(addr)]) => ctx.and_then(|global| {
let addr = *addr + memory.offset;
let addr = addr.checked_add(memory.offset)?;
if addr.checked_add(4)? > global.memories[memory.memory].data.len() as u32 {
return None;
}
@ -956,7 +956,7 @@ pub fn const_eval(
)))
}),
(Operator::I64Load { memory }, [ConstVal::I32(addr)]) => ctx.and_then(|global| {
let addr = *addr + memory.offset;
let addr = addr.checked_add(memory.offset)?;
if addr.checked_add(8)? > global.memories[memory.memory].data.len() as u32 {
return None;
}
@ -966,7 +966,7 @@ pub fn const_eval(
)))
}),
(Operator::F32Load { memory }, [ConstVal::I32(addr)]) => ctx.and_then(|global| {
let addr = *addr + memory.offset;
let addr = addr.checked_add(memory.offset)?;
if addr.checked_add(4)? > global.memories[memory.memory].data.len() as u32 {
return None;
}
@ -976,7 +976,7 @@ pub fn const_eval(
)))
}),
(Operator::F64Load { memory }, [ConstVal::I32(addr)]) => ctx.and_then(|global| {
let addr = *addr + memory.offset;
let addr = addr.checked_add(memory.offset)?;
if addr.checked_add(8)? > global.memories[memory.memory].data.len() as u32 {
return None;
}
@ -986,7 +986,7 @@ pub fn const_eval(
)))
}),
(Operator::I32Load8S { memory }, [ConstVal::I32(addr)]) => ctx.and_then(|global| {
let addr = *addr + memory.offset;
let addr = addr.checked_add(memory.offset)?;
if addr.checked_add(1)? > global.memories[memory.memory].data.len() as u32 {
return None;
}
@ -995,7 +995,7 @@ pub fn const_eval(
))
}),
(Operator::I32Load8U { memory }, [ConstVal::I32(addr)]) => ctx.and_then(|global| {
let addr = *addr + memory.offset;
let addr = addr.checked_add(memory.offset)?;
if addr.checked_add(4)? > global.memories[memory.memory].data.len() as u32 {
return None;
}
@ -1004,7 +1004,7 @@ pub fn const_eval(
))
}),
(Operator::I32Load16S { memory }, [ConstVal::I32(addr)]) => ctx.and_then(|global| {
let addr = *addr + memory.offset;
let addr = addr.checked_add(memory.offset)?;
if addr.checked_add(2)? > global.memories[memory.memory].data.len() as u32 {
return None;
}
@ -1013,7 +1013,7 @@ pub fn const_eval(
))
}),
(Operator::I32Load16U { memory }, [ConstVal::I32(addr)]) => ctx.and_then(|global| {
let addr = *addr + memory.offset;
let addr = addr.checked_add(memory.offset)?;
if addr.checked_add(2)? > global.memories[memory.memory].data.len() as u32 {
return None;
}
@ -1022,7 +1022,7 @@ pub fn const_eval(
))
}),
(Operator::I64Load8S { memory }, [ConstVal::I32(addr)]) => ctx.and_then(|global| {
let addr = *addr + memory.offset;
let addr = addr.checked_add(memory.offset)?;
if addr.checked_add(1)? > global.memories[memory.memory].data.len() as u32 {
return None;
}
@ -1031,7 +1031,7 @@ pub fn const_eval(
))
}),
(Operator::I64Load8U { memory }, [ConstVal::I32(addr)]) => ctx.and_then(|global| {
let addr = *addr + memory.offset;
let addr = addr.checked_add(memory.offset)?;
if addr.checked_add(1)? > global.memories[memory.memory].data.len() as u32 {
return None;
}
@ -1040,7 +1040,7 @@ pub fn const_eval(
))
}),
(Operator::I64Load16S { memory }, [ConstVal::I32(addr)]) => ctx.and_then(|global| {
let addr = *addr + memory.offset;
let addr = addr.checked_add(memory.offset)?;
if addr.checked_add(2)? > global.memories[memory.memory].data.len() as u32 {
return None;
}
@ -1049,7 +1049,7 @@ pub fn const_eval(
))
}),
(Operator::I64Load16U { memory }, [ConstVal::I32(addr)]) => ctx.and_then(|global| {
let addr = *addr + memory.offset;
let addr = addr.checked_add(memory.offset)?;
if addr.checked_add(2)? > global.memories[memory.memory].data.len() as u32 {
return None;
}
@ -1058,7 +1058,7 @@ pub fn const_eval(
))
}),
(Operator::I64Load32S { memory }, [ConstVal::I32(addr)]) => ctx.and_then(|global| {
let addr = *addr + memory.offset;
let addr = addr.checked_add(memory.offset)?;
if addr.checked_add(4)? > global.memories[memory.memory].data.len() as u32 {
return None;
}
@ -1067,7 +1067,7 @@ pub fn const_eval(
))
}),
(Operator::I64Load32U { memory }, [ConstVal::I32(addr)]) => ctx.and_then(|global| {
let addr = *addr + memory.offset;
let addr = addr.checked_add(memory.offset)?;
if addr.checked_add(4)? > global.memories[memory.memory].data.len() as u32 {
return None;
}
@ -1077,7 +1077,7 @@ pub fn const_eval(
}),
(Operator::I32Store { memory }, [ConstVal::I32(addr), ConstVal::I32(data)]) => ctx
.and_then(|global| {
let addr = *addr + memory.offset;
let addr = addr.checked_add(memory.offset)?;
if addr.checked_add(4)? > global.memories[memory.memory].data.len() as u32 {
return None;
}
@ -1086,7 +1086,7 @@ pub fn const_eval(
}),
(Operator::I64Store { memory }, [ConstVal::I32(addr), ConstVal::I64(data)]) => ctx
.and_then(|global| {
let addr = *addr + memory.offset;
let addr = addr.checked_add(memory.offset)?;
if addr.checked_add(8)? > global.memories[memory.memory].data.len() as u32 {
return None;
}
@ -1095,7 +1095,7 @@ pub fn const_eval(
}),
(Operator::I32Store8 { memory }, [ConstVal::I32(addr), ConstVal::I32(data)]) => ctx
.and_then(|global| {
let addr = *addr + memory.offset;
let addr = addr.checked_add(memory.offset)?;
if addr.checked_add(1)? > global.memories[memory.memory].data.len() as u32 {
return None;
}
@ -1104,7 +1104,7 @@ pub fn const_eval(
}),
(Operator::I32Store16 { memory }, [ConstVal::I32(addr), ConstVal::I32(data)]) => ctx
.and_then(|global| {
let addr = *addr + memory.offset;
let addr = addr.checked_add(memory.offset)?;
if addr.checked_add(2)? > global.memories[memory.memory].data.len() as u32 {
return None;
}
@ -1113,7 +1113,7 @@ pub fn const_eval(
}),
(Operator::I64Store8 { memory }, [ConstVal::I32(addr), ConstVal::I64(data)]) => ctx
.and_then(|global| {
let addr = *addr + memory.offset;
let addr = addr.checked_add(memory.offset)?;
if addr.checked_add(1)? > global.memories[memory.memory].data.len() as u32 {
return None;
}
@ -1122,7 +1122,7 @@ pub fn const_eval(
}),
(Operator::I64Store16 { memory }, [ConstVal::I32(addr), ConstVal::I64(data)]) => ctx
.and_then(|global| {
let addr = *addr + memory.offset;
let addr = addr.checked_add(memory.offset)?;
if addr.checked_add(2)? > global.memories[memory.memory].data.len() as u32 {
return None;
}
@ -1131,7 +1131,7 @@ pub fn const_eval(
}),
(Operator::I64Store32 { memory }, [ConstVal::I32(addr), ConstVal::I64(data)]) => ctx
.and_then(|global| {
let addr = *addr + memory.offset;
let addr = addr.checked_add(memory.offset)?;
if addr.checked_add(4)? > global.memories[memory.memory].data.len() as u32 {
return None;
}
@ -1140,7 +1140,7 @@ pub fn const_eval(
}),
(Operator::F32Store { memory }, [ConstVal::I32(addr), ConstVal::F32(data)]) => ctx
.and_then(|global| {
let addr = *addr + memory.offset;
let addr = addr.checked_add(memory.offset)?;
if addr.checked_add(4)? > global.memories[memory.memory].data.len() as u32 {
return None;
}
@ -1149,7 +1149,7 @@ pub fn const_eval(
}),
(Operator::F64Store { memory }, [ConstVal::I32(addr), ConstVal::F64(data)]) => ctx
.and_then(|global| {
let addr = *addr + memory.offset;
let addr = addr.checked_add(memory.offset)?;
if addr.checked_add(8)? > global.memories[memory.memory].data.len() as u32 {
return None;
}