Skip to content

Commit

Permalink
fix(lib) prevent a segfault loading an empty .wat module with V8
Browse files Browse the repository at this point in the history
Fixing it at the ngx-wasm-rs level produces a more descriptive error
message than doing it at the C level.

Fix #543
  • Loading branch information
thibaultcha committed May 5, 2024
1 parent 8ac549f commit 8799cc9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/ngx-wasm-rs/lib/wat/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ pub unsafe extern "C" fn ngx_wasm_wat_to_wasm(
wat: *const wasm_byte_vec_t,
wasm: *mut wasm_byte_vec_t,
) -> Option<Box<wasm_byte_vec_t>> {
let wat_slice;
let empty = Vec::new();
let mut wat_slice = empty.as_ref();

unsafe {
wat_slice = std::slice::from_raw_parts((*wat).data, (*wat).size);
if (*wat).size > 0 {
wat_slice = std::slice::from_raw_parts((*wat).data, (*wat).size);
}
}

match wabt::wat2wasm(wat_slice) {
Expand Down

0 comments on commit 8799cc9

Please sign in to comment.