Skip to content

[interp] Fix out-of-bounds read tracing call_ref and return_call_ref - #2819

Merged
sbc100 merged 1 commit into
WebAssembly:mainfrom
aizu-m:istream-call-ref-kind
Aug 12, 2026
Merged

sbc100 merged 1 commit into
WebAssembly:mainfrom
aizu-m:istream-call-ref-kind

Conversation

@aizu-m

@aizu-m aizu-m commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Istream::Read never initialises Instr::kind for call_ref/return_call_ref though both are emitted into the istream, so under --trace the tracer decodes them with the previous instruction's kind and Pick() reads past the end of the value stack; give them Imm_0_Op_1 (no immediate, one operand: the callee reference) like the other reachable opcodes.

@sbc100 sbc100 changed the title Fix out-of-bounds read tracing call_ref and return_call_ref [interp] Fix out-of-bounds read tracing call_ref and return_call_ref Aug 11, 2026
@sbc100
sbc100 requested a review from zherczeg August 11, 2026 06:42

@zherczeg zherczeg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Good catch!

#0. 24: V:1 | i32.const 0
#0. 32: V:2 | i32.const 0
#0. 40: V:3 | i32.store $0:0+$0, 0
#0. 56: V:1 | call_ref ?

@zherczeg zherczeg Aug 11, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is the '?' valid?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's expected. call_ref and return_call_ref carry no operand types in opcode.def (the params are all ___), so TraceSource::Pick works out num_operands as 0, treats the type as Void, and the switch on instr.op has no case for them, so it returns "?". Any opcode without recorded param types traces the same way. The value under it is the callee funcref, the tracer just has no static type to print for it. Showing funcref:N there would mean recording the operand type, which is the TODO already sitting above Pick. The point of this patch is only that the kind is set at all, so Pick(1) reads the real top of stack instead of a stale two-operand kind.

@zherczeg zherczeg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@sbc100
sbc100 merged commit 09cf917 into WebAssembly:main Aug 12, 2026
17 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.

3 participants