Skip to content

Fix CodeValidator null deref after final END pops control stack#573

Merged
titzer merged 3 commits intotitzer:masterfrom
sumleo:fix/codevalidator-empty-ctlstack
Mar 4, 2026
Merged

Fix CodeValidator null deref after final END pops control stack#573
titzer merged 3 commits intotitzer:masterfrom
sumleo:fix/codevalidator-empty-ctlstack

Conversation

@sumleo
Copy link
Contributor

@sumleo sumleo commented Feb 25, 2026

Summary

  • After the final END opcode pops the last control frame, ctl_stack.peek() is called to set ctl_top, but the stack is empty, resulting in a null dereference on subsequent opcode processing.

Details

CodeValidator.v3:373 — the codeptr.reset() (to stop processing) was only applied when validatingInitExpr was true. Make the empty-stack check unconditional so normal function validation also stops after the final END.

After the final END opcode pops the last control frame, ctl_stack is
empty but ctl_stack.peek() is called unconditionally to set ctl_top,
resulting in a null dereference on subsequent opcode processing.

The codeptr reset (to stop processing) was only applied when
validatingInitExpr was true. Make the empty-stack check unconditional
so that normal function validation also stops after the final END.
@sumleo sumleo force-pushed the fix/codevalidator-empty-ctlstack branch from 5fdefc2 to af0a44c Compare February 25, 2026 14:33
Copy link
Owner

@titzer titzer left a comment

Choose a reason for hiding this comment

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

Thanks, can you please add a regression test for this case?

sumleo and others added 2 commits March 4, 2026 21:55
Tests that the validator does not crash when the final END pops
the last control frame and trailing bytes remain in the body.
Comment change to trigger CI rerun.
@titzer titzer merged commit 8b932dd into titzer:master Mar 4, 2026
12 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