Fix throw_ref missing null check on exnref#567
Merged
titzer merged 4 commits intotitzer:masterfrom Mar 5, 2026
Merged
Conversation
THROW_REF pops an exnref and rethrows it, but does not check for null before casting with Exception.!(exval.val). A null exnref causes a crash instead of properly trapping with NULL_DEREF. Add null check before the cast to trap correctly.
titzer
approved these changes
Mar 3, 2026
Owner
titzer
left a comment
There was a problem hiding this comment.
Thanks, can you add a regression test for this case?
Verifies that throw_ref with a null exnref properly traps with null dereference instead of crashing.
Comment change to trigger CI
titzer
reviewed
Mar 4, 2026
| } | ||
| THROW_REF => { | ||
| var exval = popr(); | ||
| if (exval.val == null) return void(trap(TrapReason.NULL_DEREF)); |
Owner
There was a problem hiding this comment.
The regression test caught a bug in the fast interpreter, which calls into the runtime to do a throw. So we also need a line in X86_64Runtime.runtime_THROW_REF to check for null as well.
The fast interpreter runtime also needs to check for null throwable before calling stack.throw(), matching the V3Interpreter null check.
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.
Summary
THROW_REFpops an exnref and rethrows it but does not check for null before casting withException.!(exval.val), causing a crash on null exnref instead of trapping withNULL_DEREF.Details
V3Interpreter.v3:330— add a null check before the forced cast.