fix: 添加 vm 循环次数上限以避免测试死循环
This commit is contained in:
@@ -176,7 +176,13 @@ impl Vm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch(&mut self) -> Result<JsValue, String> {
|
fn dispatch(&mut self) -> Result<JsValue, String> {
|
||||||
|
let mut steps: u64 = 0;
|
||||||
|
const MAX_STEPS: u64 = 100_000_000;
|
||||||
loop {
|
loop {
|
||||||
|
steps += 1;
|
||||||
|
if steps > MAX_STEPS {
|
||||||
|
return Err(format!("VM step limit exceeded at pc={}", self.pc));
|
||||||
|
}
|
||||||
if self.pc >= self.bytecode.len() {
|
if self.pc >= self.bytecode.len() {
|
||||||
return Err("program counter out of bounds".into());
|
return Err("program counter out of bounds".into());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user