When tsify fails to parse the argument passed, it throws an error which causes a memory leak on Rust side. Which eventually causes a memory access out of bounds to be thrown, irrecoverably killing the WASM instance.
Reproducer here: https://github.com/utdemir/tsify-leak-repro
I dug in a bit and here's what I think happens: #[tsify(from_wasm_abi)] generates a FromWasmABI implementation which uses throw_str when parsing fails. Which has a note in docs:
Note that it is very easy to leak memory with this function because this function, unlike panic! on other platforms, will not run destructors. It’s recommended to return a Result where possible to avoid the worry of leaks.
From a cursory look - I don't think FromWasmABI is meant to be used with fallible conversions. So unsure what the proper fix would be other than significantly changing the tsify interface. Or coordinating with wasm_bindgen folks to allow partial FromWasmABI implementations.
When
tsifyfails to parse the argument passed, it throws an error which causes a memory leak on Rust side. Which eventually causes amemory access out of boundsto be thrown, irrecoverably killing the WASM instance.Reproducer here: https://github.com/utdemir/tsify-leak-repro
I dug in a bit and here's what I think happens:
#[tsify(from_wasm_abi)]generates aFromWasmABIimplementation which uses throw_str when parsing fails. Which has a note in docs:From a cursory look - I don't think
FromWasmABIis meant to be used with fallible conversions. So unsure what the proper fix would be other than significantly changing thetsifyinterface. Or coordinating withwasm_bindgenfolks to allow partialFromWasmABIimplementations.