Skip to content

Fix wrong iterator variable in InterpDropKeep ref tracking#2702

Merged
sbc100 merged 1 commit into
WebAssembly:mainfrom
sumleo:fix/interp-dropkeep-ref-iter
Feb 25, 2026
Merged

Fix wrong iterator variable in InterpDropKeep ref tracking#2702
sbc100 merged 1 commit into
WebAssembly:mainfrom
sumleo:fix/interp-dropkeep-ref-iter

Conversation

@sumleo

@sumleo sumleo commented Feb 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fix a bug in the InterpDropKeep handler in src/interp/interp.cc where the "find dropped refs" loop checked *iter instead of *drop_iter

Problem

In the InterpDropKeep opcode handler, after shifting kept refs down, a second loop scans for refs that fall in the dropped value range so they can be erased. However, the loop condition on line 1687 dereferenced iter (the end position of the previous loop) rather than drop_iter (the current loop's iterator).

Because iter is never advanced in the second loop, the condition is loop-invariant: it either breaks immediately on the first iteration or never breaks at all. This means refs pointing into the dropped range may not be properly identified and erased from refs_, leaving stale indices that can cause out-of-bounds access when Thread::Mark() walks refs_ during garbage collection.

Fix

Change *iter to *drop_iter on the condition line so the loop correctly inspects each candidate ref index.

Test plan

  • Build passes (cmake --build build --target wabt-unittests)
  • Verified by code inspection that drop_iter is the intended loop variable

In the "find dropped refs" loop of the InterpDropKeep handler, the
condition checked `*iter` (the final position of the previous loop's
iterator) instead of `*drop_iter` (the current loop's iterator). Since
`iter` is not advanced in this loop, the condition was loop-invariant:
it either always broke on the first iteration or never broke at all.

This caused stale ref indices from the dropped value range to remain
in `refs_`, which could lead to out-of-bounds access during garbage
collection in Thread::Mark().
@sbc100 sbc100 merged commit b8d1aa8 into WebAssembly:main Feb 25, 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.

2 participants