Convert non-error panics to errors in protect - #144
Open
nopcoder wants to merge 1 commit into
Open
Conversation
protect() asserted that every recovered value is an error, but the VM
panics with plain strings in many places (panic("unreachable"),
panic("XMove not implemented yet"), the "expected opcode" invariants in
the bytecode interpreter). Any of those turned into a second panic -
"interface conversion: string is not error" - crashing the host and
losing the original message.
Pass real errors through unchanged and wrap anything else with
fmt.Errorf, so a protected call always returns an error.
nopcoder
force-pushed
the
protect-non-error-panic
branch
from
August 25, 2026 08:58
c16d32d to
2bcaad4
Compare
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.
Running Lua code can panic the host Go program.
protect()recovers a panic and asserts the value is anerror:But the VM panics with plain strings all over —
panic("unreachable"),panic("XMove not implemented yet"),"expected opcode %s, got %s"in the interpreter. Those hit the type assertion and panic again, so the panic escapesProtectedCalland takes down the process:The bytecode invariants (
expected opcode,opExtraArg) are reachable fromload()of an untrusted binary chunk.Fix: pass errors through unchanged, wrap anything else with
fmt.Errorf, so a protected call always returns an error instead of panicking.TestPanicWithStringdrivesdebug.gethook()(apanic("string")site) throughProtectedCall— it panics without the fix, returns an error with it.