alexcrichton opened PR #14487 from alexcrichton:fix-fd-readdir to bytecodealliance:main:
This commit is a fix to the implementation of the WASIp1 function
fd_readdir. This notably removes theunsafeinternally used to implement the function. Previously the hostDirentstucture was copied as-is to the guest, but this had two independent bugs. First the host's undefined padding bytes were copied to the guest meaning that up to 3 bytes of host memory was leaked to the guest. Second was that the host structure wasn't tagged#[repr(C)]so future versions of a Rust compiler could reorder the structure's fields.The fix here is to manually serialize the
Direntinto a host-side buffer. This serialization is now all done withoutunsafemeaning the everything is fully defined, notably padding bytes are unconditionally defined as zero now.<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease review the Bytecode Alliance's AI tool usage policy at
https://github.com/bytecodealliance/governance/blob/main/AI_TOOL_POLICY.mdPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
alexcrichton requested pchickey for a review on PR #14487.
alexcrichton requested wasmtime-wasi-reviewers for a review on PR #14487.
:thumbs_up: adamrk submitted PR review.
github-actions[bot] added the label wasi on PR #14487.
alexcrichton added PR #14487 Fix leaking host padding bytes to guests in fd_readdir to the merge queue
:check: alexcrichton merged PR #14487.
alexcrichton removed PR #14487 Fix leaking host padding bytes to guests in fd_readdir from the merge queue
Last updated: Oct 11 2026 at 04:10 UTC