ViktorByteTZ opened PR #14931 from ViktorByteTZ:fix-table-grow-unrooted-14582 to bytecodealliance:main:
Closes #14582.
Summary
When
Table::growis invoked with an unrootedRootedGC reference (such asExternRef,AnyRef, orExnRef),ensure_matches_typreviously returnedOk(())for top heap types without verifying that the reference was still rooted. As a result, growth proceeded and the subsequent_fillstep encountered an unrooted error duringinto_table_gc_ref, which triggered anunwrap()panic on a grown table.Changes
- In
Ref::_matches_tyandRef::load_ty, calltry_gc_ref(store)when matchingExtern,Any, andExnagainst their respective top heap types. This enforces the documented contract ofmatches_ty("Returns an error if the underlyingRootedhas been unrooted") upfront before table reallocation occurs.- In
Table::_grow, propagate errors from_fillwith?instead of panicking.- Added a unit test in
runtime::externals::table::testsverifying thatTable::growwith an unrooted reference returnsErrwithout panicking and preserves the original table size.
ViktorByteTZ removed the review request for wasmtime-core-reviewers from PR #14931.
ViktorByteTZ requested pchickey for a review on PR #14931.
ViktorByteTZ requested wasmtime-core-reviewers for a review on PR #14931.
:memo: alexcrichton submitted PR review.
:speech_balloon: alexcrichton created PR review comment:
This'll want to stay as
.unwrap()as if this fails then it could be possible for a table to have grown but not been filled, which is not good for tables of non-null elements. This.unwrap()is load-bearing in that sense to promote mistakes (like the rooting you're fixing here) to panics as opposed to more serious memory safety vulnerabilities.
github-actions[bot] added the label wasmtime:api on PR #14931.
pchickey removed the review request for pchickey from PR #14931.
ViktorByteTZ updated PR #14931.
:memo: ViktorByteTZ submitted PR review.
:speech_balloon: ViktorByteTZ created PR review comment:
Good point, agreed! Kept the .unwrap() in Table::_grow so that any post-growth fill failure promotes to a panic to preserve the non-null table invariant, with ensure_matches_ty catching unrooted references beforehand.
:thumbs_up: alexcrichton submitted PR review.
alexcrichton has enabled auto merge for PR #14931.
alexcrichton added PR #14931 Fix Table::grow panic on unrooted GC init reference to the merge queue.
github-merge-queue[bot] removed PR #14931 Fix Table::grow panic on unrooted GC init reference from the merge queue.
alexcrichton added PR #14931 Fix Table::grow panic on unrooted GC init reference to the merge queue.
github-merge-queue[bot] removed PR #14931 Fix Table::grow panic on unrooted GC init reference from the merge queue.
alexcrichton added PR #14931 Fix Table::grow panic on unrooted GC init reference to the merge queue.
:check: alexcrichton merged PR #14931.
alexcrichton removed PR #14931 Fix Table::grow panic on unrooted GC init reference from the merge queue.
Last updated: Oct 31 2026 at 23:03 UTC