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

Panics in return value encoding crash the VM #655

Closed
ethanwu10 opened this issue Oct 11, 2024 · 1 comment · Fixed by #656
Closed

Panics in return value encoding crash the VM #655

ethanwu10 opened this issue Oct 11, 2024 · 1 comment · Fixed by #656

Comments

@ethanwu10
Copy link

If the implementation of rustler::Encoder::encode panics during encoding of a return value from a #[rustler::nif] method, the panic is not caught and brings down the whole VM.

In the implementation of the nif macro, return value conversion is handled outside of the catch_unwind block:

std::panic::catch_unwind(move || {
#decoded_terms
#function
Ok(#name(#argument_names))
});
rustler::codegen_runtime::handle_nif_result(
result, env
)

While this is necessary to convert a caught panic from within the NIF function itself (which is rustler code and thus can be assumed to not panic), this also puts encoding for normal return values with library-user-controlled Encoder implementations outside the catch_unwind.

As an example, I happened to run into this when using a malformed SerdeTerm as a return value; the serde code panicked and brought down the VM.

@filmor
Copy link
Member

filmor commented Oct 11, 2024

You are right, this is an oversight.

filmor added a commit that referenced this issue Oct 11, 2024
Also adds tests for panicking in parameters, return values and the NIF
function itself.

Fixes #655
filmor added a commit that referenced this issue Oct 11, 2024
Also adds tests for panicking in parameters, return values and the NIF
function itself.

Fixes #655
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants