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,TableTypeandMemoryTypecache aRef refnext to the owningptr, andoperator->andoperator*hand out that cachedref. Their copy assignment replaces the owned object withptr.reset(...)but does not updateref, so afterb = athe cached pointer still refers to the objectresetjust freed, andb->params()reads freed memory. This needs nothing more unusual than assigning one existing value to another.__asan_describe_addresson the pointer held byrefreports it as freed insideFuncType::operator=, and a debug build aborts inty():crates/c-api/src/types/func.rs:115:27: unsafe precondition(s) violated: hint::unreachable_unchecked must never be reachedMove assignment copies
refalong withptr, and the existing tests assign from temporaries, which is likely why this went unnoticed.func_type.ccdoes copy-assign, but never reads the result.The fix adds
ref = ptr.get();to all four operators, which is whatTagTypeandValTypealready do. Those two are the only other classes with a cachedRef. Only use through->or*should be affected, since the other paths readptrdirectly. 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
CopyAssigntest for each type. All four abort without the fix and pass with it. The C API job'sninja 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.
netliomax25-code removed the review request for wasmtime-core-reviewers from PR #15109.
netliomax25-code requested pchickey for a review on PR #15109.
netliomax25-code requested wasmtime-core-reviewers for a review on PR #15109.
github-actions[bot] added the label wasmtime:c-api on PR #15109.
:cross_mark: alexcrichton closed without merge PR #15109.
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