Skip to content

Fix missing IS_INVALID_TAGINDEX check in RETHROW handler#4837

Open
sumleo wants to merge 1 commit intobytecodealliance:mainfrom
sumleo:fix/rethrow-tag-index-validation
Open

Fix missing IS_INVALID_TAGINDEX check in RETHROW handler#4837
sumleo wants to merge 1 commit intobytecodealliance:mainfrom
sumleo:fix/rethrow-tag-index-validation

Conversation

@sumleo
Copy link
Contributor

@sumleo sumleo commented Feb 12, 2026

The RETHROW opcode handler reads exception_tag_index from the stack and directly accesses module->module->tags[exception_tag_index] without checking for INVALID_TAGINDEX.

When CATCH_ALL catches a cross-module exception with an unknown tag, it pushes INVALID_TAGINDEX (0xFFFFFFFF) onto the stack. If RETHROW then executes, it accesses tags[0xFFFFFFFF] — a massive out-of-bounds read.

The THROW handler correctly checks IS_INVALID_TAGINDEX before the array access. This patch adds the same check to the RETHROW handler: when the tag index is invalid, skip the tags[] access and set cell_num_to_copy to 0, allowing the exception to propagate to CATCH_ALL handlers.

The RETHROW opcode handler in the classic interpreter reads the
exception_tag_index from the stack and directly uses it to index
module->module->tags[] without checking IS_INVALID_TAGINDEX first.

When CATCH_ALL catches a cross-module exception, it pushes
INVALID_TAGINDEX (0xFFFFFFFF) onto the stack. If RETHROW then executes,
it reads 0xFFFFFFFF and accesses tags[0xFFFFFFFF], causing a massive
out-of-bounds read.

The THROW handler at line 1744 properly checks IS_INVALID_TAGINDEX
before accessing the tags array. Add the same check to the RETHROW
handler: when IS_INVALID_TAGINDEX is true, skip the tags[] access and
set cell_num_to_copy to 0, allowing the exception to propagate to
CATCH_ALL handlers.

Add unit tests verifying IS_INVALID_TAGINDEX detection and that
RETHROW uses the same validation logic as THROW.
@sumleo sumleo force-pushed the fix/rethrow-tag-index-validation branch from 4de4f92 to bb89991 Compare February 13, 2026 14:39
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