Skip to content

Fix DRC panic when overwriting an i31ref slot#13307

Open
vouillon wants to merge 2 commits intobytecodealliance:mainfrom
vouillon:fix
Open

Fix DRC panic when overwriting an i31ref slot#13307
vouillon wants to merge 2 commits intobytecodealliance:mainfrom
vouillon:fix

Conversation

@vouillon
Copy link
Copy Markdown

@vouillon vouillon commented May 6, 2026

Add an i31 early-return at the entry of DrcHeap::dec_ref_and_maybe_dealloc, matching the behavior of the original dec_ref helper.

dec_ref_and_maybe_dealloc lost its i31ref early-return when dec_ref was inlined into the deallocation loop (commit 5cca437 in #12974), replacing the runtime check with a debug_assert!(!gc_ref.is_i31()). Callers like write_gc_ref (used by libcalls such as array.copy) hand the destination ref directly to dec_ref_and_maybe_dealloc without filtering i31s, so any write that overwrites an i31ref slot trips the assertion.

vouillon added 2 commits May 6, 2026 22:58
Creates an `(array (mut anyref))` whose destination slots hold
`i31ref`s and whose source slots hold `structref`s, then runs
`array.copy`. Each element write hits the DRC `write_gc_ref` with
`dest = Some(i31ref)` and a non-`i31ref` source: the higher-level
write-barrier filter sees a real GC object on the source side and
dispatches into the heap's barrier, which dec-refs the destination
`i31ref`. Without the accompanying fix, this trips
`debug_assert!(!gc_ref.is_i31())` inside
`DrcHeap::dec_ref_and_maybe_dealloc`.
`DrcHeap::dec_ref_and_maybe_dealloc` lost its i31ref early-return when
`dec_ref` was inlined into the deallocation loop, replacing the runtime
check with a `debug_assert!(!gc_ref.is_i31())`. Callers like
`write_gc_ref` (used by libcalls such as `array.copy`) hand the
destination ref directly to `dec_ref_and_maybe_dealloc` without
filtering i31s, so any write that overwrites an i31ref slot trips the
assertion.

Restore the i31 early-return at the entry of
`dec_ref_and_maybe_dealloc`, matching the behavior of the original
`dec_ref` helper.
@vouillon vouillon requested a review from a team as a code owner May 6, 2026 21:12
@vouillon vouillon requested review from pchickey and removed request for a team May 6, 2026 21:12
@github-actions github-actions Bot added wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:ref-types Issues related to reference types and GC in Wasmtime labels May 6, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

Subscribe to Label Action

cc @fitzgen

Details This issue or pull request has been labeled: "wasmtime:api", "wasmtime:ref-types"

Thus the following users have been cc'd because of the following labels:

  • fitzgen: wasmtime:ref-types

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:ref-types Issues related to reference types and GC in Wasmtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant