Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow module-level middleware to return an error to cancel compilation #5010

Closed
damip opened this issue Aug 13, 2024 · 0 comments · Fixed by #5011
Closed

Allow module-level middleware to return an error to cancel compilation #5010

damip opened this issue Aug 13, 2024 · 0 comments · Fixed by #5011
Labels
🎉 enhancement New feature!

Comments

@damip
Copy link
Contributor

damip commented Aug 13, 2024

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, 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎉 enhancement New feature!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant