Skip to content

Convert non-error panics to errors in protect - #144

Open
nopcoder wants to merge 1 commit into
Shopify:mainfrom
nopcoder:protect-non-error-panic
Open

Convert non-error panics to errors in protect#144
nopcoder wants to merge 1 commit into
Shopify:mainfrom
nopcoder:protect-non-error-panic

Conversation

@nopcoder

@nopcoder nopcoder commented Aug 25, 2026

Copy link
Copy Markdown

Running Lua code can panic the host Go program. protect() recovers a panic and asserts the value is an error:

err = e.(error)

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 escapes ProtectedCall and takes down the process:

panic: XMove not implemented yet [recovered]
	panic: interface conversion: string is not error: missing method Error [recovered, repanicked]

The bytecode invariants (expected opcode, opExtraArg) are reachable from load() 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.

TestPanicWithString drives debug.gethook() (a panic("string") site) through ProtectedCall — it panics without the fix, returns an error with it.

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
nopcoder force-pushed the protect-non-error-panic branch from c16d32d to 2bcaad4 Compare August 25, 2026 08:58
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.

1 participant