netliomax25-code opened PR #15291 from netliomax25-code:wasi-nn-winml-tensor-decode to bytecodealliance:main:
to_inspectablein the WinML backend turns an input tensor'sVec<u8>into&[f32]/&[i64]withslice::from_raw_parts(tensor.data.as_ptr().cast::<T>(), ...). AVec<u8>only guarantees 1-byte alignment, so building that slice is undefined behavior unless the allocator happens to hand back a suitably aligned block. Thecheck_alignmentcall after it can't catch a misaligned buffer: it runsalign_to::<T>()on a slice that is already&[T], so prefix and suffix are always empty, and the UB has already happened by then anyway.Running the same construct under Miri with
-Zmiri-symbolic-alignment-checkreportsconstructing invalid value of type &[f32]: encountered an unaligned reference (required 4 byte alignment but found 1).The elements are now decoded with
chunks_exact+from_le_bytes, the same encodingto_tensorand the ONNX backend'sbytes_to_f32_vecalready use, so theunsafeblocks andcheck_alignmentgo away. Values are unchanged on Windows (little-endian), and a trailing partial element is still ignored as before. wasi-nn is tier 3, so as far as I can tell this is not a security issue under Wasmtime's policy.Verification:
cargo checkandcargo clippyofwasmtime-wasi-nn(lib + tests, default features,-D warnings) forx86_64-pc-windows-msvcare clean, rustfmt is clean, and the new helper passes the same Miri run. I could only cross-check from a non-Windows machine, so the existingfp16/fp32/i64round-trip unit tests inwinml.rswere compiled but not executed here; CI's Windows job should cover them.
netliomax25-code removed the review request for wasmtime-wasi-reviewers from PR #15291.
netliomax25-code requested rvolosatovs for a review on PR #15291.
netliomax25-code requested wasmtime-wasi-reviewers for a review on PR #15291.
alexcrichton removed the review request for rvolosatovs from PR #15291.
alexcrichton commented on PR #15291:
cc @rahulchaphalkar @jlb6740
Last updated: Nov 19 2026 at 20:05 UTC