Skip to content

Conversation

@Echo8377
Copy link
Contributor

No description provided.

Comment on lines 430 to 448
// Use checked arithmetic to prevent integer overflow
let offset = insn.imm as isize;
if offset < 0 {
let abs_offset = (-offset) as usize;
if abs_offset > insn_ptr {
Err(Error::other(format!(
"Error: call offset underflow (insn #{})",
insn_ptr - 1
)))?;
}
insn_ptr -= abs_offset;
} else {
insn_ptr = insn_ptr.checked_add(offset as usize).ok_or_else(|| {
Error::other(format!(
"Error: call offset overflow (insn #{})",
insn_ptr - 1
))
})?;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we work with immediate values, we know the value at verification time, and we shouldn't be doing these checks at runtime, we should do it in src/verifier.rs instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we work with immediate values, we know the value at verification time, and we shouldn't be doing these checks at runtime, we should do it in src/verifier.rs instead.

You're right about avoiding runtime checks. I checked verifier.rs and realized your original code was already solid and handles these bounds correctly. So I've removed the redundant check from interpreter.rs to restore the efficient behavior.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked verifier.rs and realized your original code was already solid and handles these bounds correctly

I don't think it does, I tried your reproducer yesterday and the code in the verifier doesn't prevent the overflow in debug mode. We should probably reject the program in that case. But I can look into it at some point as well, I didn't have time yesterday.

Copy link
Owner

@qmonnet qmonnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@qmonnet qmonnet merged commit a54b100 into qmonnet:main Jan 15, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants