This commit is contained in:
bQUARKz 2026-02-10 08:33:03 +00:00
parent 1a8ec25c07
commit 99f024eaa9
Signed by: bquarkz
SSH Key Fingerprint: SHA256:Z7dgqoglWwoK6j6u4QC87OveEq74WOhFN+gitsxtkf8

View File

@ -263,6 +263,27 @@ mod tests {
assert_eq!(res, Err(VerifierError::JumpToMidInstruction { pc: 6, target: 1 }));
}
#[test]
fn test_verifier_jump_to_end_ok() {
// Single-instruction function where JMP targets exactly func_len (end-exclusive)
// Encoding: [JMP][u32 imm], with imm == total function length (6 bytes)
let mut code = Vec::new();
code.push(OpCode::Jmp as u8);
code.push(0x00);
code.extend_from_slice(&6u32.to_le_bytes());
let functions = vec![FunctionMeta {
code_offset: 0,
code_len: 6,
return_slots: 0,
..Default::default()
}];
let res = Verifier::verify(&code, &functions).unwrap();
// No stack usage; max stack remains 0
assert_eq!(res[0], 0);
}
#[test]
fn test_verifier_truncation_opcode() {
let code = vec![OpCode::PushI32 as u8]; // Truncated u16 opcode