Instruction decode slice overflow on incomplete bytecode
publicqi opened this issue · 0 comments
publicqi commented
Component
Cast
Have you ensured that all of these are up to date?
- Foundry
- Foundryup
What version of Foundry are you on?
forge 0.2.0 (398ef4a 2024-11-23T00:27:34.394254000Z)
What command(s) is the bug in?
cast da 0x60
Operating System
None
Describe the bug
0x60 is PUSH1, and it's an incomplete bytecode sequence.
It will panic in crates/evm/core/src/ic.rs
/// Decodes raw opcode bytes into [`Instruction`]s.
pub fn decode_instructions(code: &[u8]) -> Vec<Instruction<'_>> {
let mut pc = 0;
let mut steps = Vec::new();
while pc < code.len() {
let op = OpCode::new(code[pc]);
let immediate_size = op.map(|op| immediate_size(op, &code[pc + 1..])).unwrap_or(0) as usize;
steps.push(Instruction { op, pc, immediate: &code[pc + 1..pc + 1 + immediate_size] });
pc += 1 + immediate_size;
}
steps
}