Skip to content

Commit 0ca4259

Browse files
committed
Fix check for sys_out_of_gas
1 parent 71b3ff5 commit 0ca4259

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

fvm/src/call_manager/default.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,10 @@ where
809809
update_gas_available(&mut store)?;
810810

811811
let mut out = [wasmtime::Val::I32(0)];
812-
func.call(&mut store, params.as_slice(), &mut out)?;
812+
let res = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
813+
func.call(&mut store, params.as_slice(), &mut out)
814+
}))
815+
.map_err(|panic| Abort::Fatal(anyhow!("panic within actor: {:?}", panic)))?;
813816

814817
// Charge for any remaining uncharged execution gas, returning an error if we run
815818
// out.
@@ -819,6 +822,10 @@ where
819822
// detected it and returned OutOfGas above. Any other invocation failure is returned
820823
// here as an Abort
821824

825+
if let Err(err) = res {
826+
return Err(err.into());
827+
}
828+
822829
Ok(out[0].unwrap_i32() as u32)
823830
})();
824831

testing/integration/tests/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,14 +589,14 @@ fn test_exitcode(wat: &str, code: ExitCode) {
589589
}
590590

591591
#[test]
592-
fn infinite_loop() {
592+
fn out_of_gas() {
593593
test_exitcode(
594594
r#"(module
595595
(memory (export "memory") 1)
596596
(func (export "invoke") (param $x i32) (result i32)
597597
(loop (br 0))
598598
(i32.const 1)))"#,
599-
ExitCode::SYS_ILLEGAL_INSTRUCTION,
599+
ExitCode::SYS_OUT_OF_GAS,
600600
)
601601
}
602602

0 commit comments

Comments
 (0)