You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We use Wasmer as the virtual machine of Massa (massa.net) and we are very happy with it.
Recently we had a security audit yielding the following issue: The following wasm file is quite small but has too many exports which causes the compilation phase to take a lot of RAM, and the resulting module is huge.
We needed a solution to limit the number of exports.
Proposed solution
We decided to implement a module-level middleware for Wasmer in Rust that checks the number of exports inside an implementation of ModuleMiddleware::transform_module_info and want that middleware pass to be able to cleanly cancel the compilation process with an error.
However, in the Wasmer ModuleMiddleware trait, the transform_module_info does not return anything, but we needed it to return a Result type and cancel the compilation process in case of error.
We need ModuleMiddleware::transform_module_info to return a Result type and be able to cleanly cancel compilation before the memory bloat happens.
Alternatives
An alternative would have been to parse the WASM file ourselves beforehand, but since Wasmer does it already it would be a waste of precious CPU time which is critical in our case.
We also thought of panicking within our middleware and use catch_unwind to catch the panic, but it does not compile because of interior mutability within Wasmer.
The text was updated successfully, but these errors were encountered:
Motivation
We use Wasmer as the virtual machine of Massa (massa.net) and we are very happy with it.
Recently we had a security audit yielding the following issue:
The following wasm file is quite small but has too many exports which causes the compilation phase to take a lot of RAM, and the resulting module is huge.
We needed a solution to limit the number of exports.
Proposed solution
We decided to implement a module-level middleware for Wasmer in Rust that checks the number of exports inside an implementation of
ModuleMiddleware::transform_module_info
and want that middleware pass to be able to cleanly cancel the compilation process with an error.However, in the Wasmer
ModuleMiddleware
trait, thetransform_module_info
does not return anything, but we needed it to return aResult
type and cancel the compilation process in case of error.We need
ModuleMiddleware::transform_module_info
to return aResult
type and be able to cleanly cancel compilation before the memory bloat happens.Alternatives
An alternative would have been to parse the WASM file ourselves beforehand, but since Wasmer does it already it would be a waste of precious CPU time which is critical in our case.
We also thought of panicking within our middleware and use
catch_unwind
to catch the panic, but it does not compile because of interior mutability within Wasmer.The text was updated successfully, but these errors were encountered: