-
Notifications
You must be signed in to change notification settings - Fork 60
Description
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.