Fix signed div overflow, call checks & add tests#213
Open
zanville wants to merge 2 commits intoOverclock-Validator:devfrom
Open
Fix signed div overflow, call checks & add tests#213zanville wants to merge 2 commits intoOverclock-Validator:devfrom
zanville wants to merge 2 commits intoOverclock-Validator:devfrom
Conversation
Avoid mutating destination registers when signed division/remainder overflows by only performing the operation in the non-overflow branch; preserve semantics for divide-by-zero errors. Improve call handling: check stack push result before changing pc, validate Callx target is inside the text segment and return a dedicated ExcCallOutsideTextSegment error on out-of-bounds. Add Exception.R to capture registers and wrap error with %w for better error inspection. Update opcode mappings for Sdiv variants and extend tests (pkg/sbpf/interpreter_test.go) to cover call depth/out-of-bounds, signed divide overflow and divide-by-zero cases.
…ator#125) stack.Pop() returns (0, false) when the call stack is empty, which overwrote pc to 0 on top-level exits. Save pc before Pop() and restore it when the stack is empty so the final register state reports the correct exit instruction address. Adds regression test TestOpExitTopLevel.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #126
Signed division overflow no longer mutates the destination register, the operation just gets skipped. Divide-by-zero behavior is unchanged.
For calls, stack push result is now checked before we update pc, and callx validates the target is actually inside the text segment. Added ExcCallOutsideTextSegment for the out-of-bounds case so it's not a mystery when it happens.
Exception now saves register state in R when a fault occurs, and errors are wrapped with %w so they're inspectable.
Also fixed the Sdiv opcode mappings and added tests for call depth, out-of-bounds callx, signed div overflow, and divide-by-zero.