netliomax25-code opened PR #14984 from netliomax25-code:c-api-wasi-null-slices to bytecodealliance:main:
wasi_config_set_argvandwasi_config_set_envbuild their slices withstd::slice::from_raw_partsdirectly on the caller's pointer and count. With a count of 0 and a NULL array this is undefined behavior in Rust, sincefrom_raw_partsrequires a non-null pointer even for an empty slice. The C++ wrapper hits it withWasiConfig::argv({})orenv({}), becausedata()of an emptystd::vectoris NULL, and a debug build of the C API aborts with:unsafe precondition(s) violated: slice::from_raw_parts requires the pointer to be aligned and non-nullThe rest of the C API already goes through
crate::slice_from_raw_parts, which returns an empty slice when the length is 0, so these three call sites now use it too. They were the only remaining directslice::from_raw_partscalls on caller-provided pointers incrates/c-api/src.I added a
WasiConfig.EmptyArgvEnvtest tocrates/c-api/tests/wasi.cc. It aborts atwasi.rs:72without the fix and passes with it, and the full C API test binary (147 tests, Debug,-DBUILD_TESTS=ON) passes on macOS aarch64.
netliomax25-code removed the review request for wasmtime-core-reviewers from PR #14984.
netliomax25-code requested wasmtime-core-reviewers for a review on PR #14984.
netliomax25-code requested dicej for a review on PR #14984.
github-actions[bot] added the label wasmtime:c-api on PR #14984.
:thumbs_up: dicej submitted PR review:
Thanks, @netliomax25-code!
dicej added PR #14984 c-api: handle NULL arrays with a zero count in wasi_config_set_argv/env to the merge queue.
:check: dicej merged PR #14984.
dicej removed PR #14984 c-api: handle NULL arrays with a zero count in wasi_config_set_argv/env from the merge queue.
Last updated: Oct 31 2026 at 23:03 UTC