Skip to content

Commit 48001a5

Browse files
authored
fix(chisel): don't panic on bad pc/memory (#12674)
1 parent 445f340 commit 48001a5

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

crates/chisel/src/executor.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,17 @@ impl SessionSource {
152152

153153
// the file compiled correctly, thus the last stack item must be the memory offset of
154154
// the `bytes memory inspectoor` value
155-
let mut offset = stack.last().unwrap().to::<usize>();
156-
let mem_offset = &memory[offset..offset + 32];
157-
let len = U256::try_from_be_slice(mem_offset).unwrap().to::<usize>();
158-
offset += 32;
159-
let data = &memory[offset..offset + len];
155+
let data = (|| -> Option<_> {
156+
let mut offset: usize = stack.last()?.try_into().ok()?;
157+
debug!("inspect memory @ {offset}: {}", hex::encode(memory));
158+
let mem_offset = memory.get(offset..offset + 32)?;
159+
let len: usize = U256::try_from_be_slice(mem_offset)?.try_into().ok()?;
160+
offset += 32;
161+
memory.get(offset..offset + len)
162+
})();
163+
let Some(data) = data else {
164+
eyre::bail!("Failed to inspect last expression: could not retrieve data from memory")
165+
};
160166
let token = ty.abi_decode(data).wrap_err("Could not decode inspected values")?;
161167
let c = if should_continue(contract_expr) {
162168
ControlFlow::Continue(())

0 commit comments

Comments
 (0)