Stream: git-wasmtime

Topic: wasmtime / PR #15109 c-api: refresh cached Ref in C++ typ...


view this post on Zulip Wasmtime GitHub notifications bot (Nov 02 2026 at 11:25):

netliomax25-code opened PR #15109 from netliomax25-code:cpp-type-ref-copy-assign to bytecodealliance:main:

Related: #15085, which fixes a different problem in other C++ copy assignment operators and does not touch these four classes.

FuncType, GlobalType, TableType and MemoryType cache a Ref ref next to the owning ptr, and operator-> and operator* hand out that cached ref. Their copy assignment replaces the owned object with ptr.reset(...) but does not update ref, so after b = a the cached pointer still refers to the object reset just freed, and b->params() reads freed memory. This needs nothing more unusual than assigning one existing value to another. __asan_describe_address on the pointer held by ref reports it as freed inside FuncType::operator=, and a debug build aborts in ty():

crates/c-api/src/types/func.rs:115:27:
unsafe precondition(s) violated: hint::unreachable_unchecked must never be reached

Move assignment copies ref along with ptr, and the existing tests assign from temporaries, which is likely why this went unnoticed. func_type.cc does copy-assign, but never reads the result.

The fix adds ref = ptr.get(); to all four operators, which is what TagType and ValType already do. Those two are the only other classes with a cached Ref. Only use through -> or * should be affected, since the other paths read ptr directly. The C++ API is tier 2 and the trigger is in embedder code, so I don't think this falls under the security process.

I added a CopyAssign test for each type. All four abort without the fix and pass with it. The C API job's ninja test (184 tests, Debug, -DBUILD_SHARED_LIBS=ON -DBUILD_TESTS=ON) passes on macOS aarch64 with and without -fsanitize=address, and clang-format 22 is clean. I have not run it on Linux or Windows.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 02 2026 at 11:25):

netliomax25-code removed the review request for wasmtime-core-reviewers from PR #15109.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 02 2026 at 11:25):

netliomax25-code requested pchickey for a review on PR #15109.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 02 2026 at 11:25):

netliomax25-code requested wasmtime-core-reviewers for a review on PR #15109.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 02 2026 at 14:44):

github-actions[bot] added the label wasmtime:c-api on PR #15109.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 02 2026 at 15:13):

:cross_mark: alexcrichton closed without merge PR #15109.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 02 2026 at 15:13):

alexcrichton commented on PR #15109:

Thanks for the PR, but this is a duplicate of https://github.com/bytecodealliance/wasmtime/pull/15098 which fixes another location as well, so I'm going to close this


Last updated: Nov 19 2026 at 20:05 UTC