Excessive allocated memory on the host when guests don't have stdio
Description
Impact
The wasmtime-wasi crate contained a bug where the write-zeros method on a specific type in the crate, SinkOutputStream, permitted an unlimited-size allocation on the host. This type is used by default for WasiCtxs that are created and represents a guest that doesn't actually print anything via stdout/stderr to the host. The write-zeroes method in the WASIp2 implementation for this type ended up not limiting the allocation made of a buffer-of-zeros to write.
This bug is related to GHSA-852m-cvvp-9p4w where the fixes applied for that advisory were intended to limit the size of host allocations, but the fix was incomplete for this specific stream and situation. Specifically the limitations previously allowed up to the size of the check-write-limit, but for SinkOutputStream the limit was previously unlimited.
This bug only affects embeddings which don't configure stdout/stderr streams. Configured streams have their own limits typically which would prevent this large allocation, but unconfigured streams use SinkOutputStream which allows an unlimited-size allocation.
Patches
This issue has been fixed in Wasmtime 36.0.17, 48.0.4, and 49.0.2. All other previously published versions of Wasmtime are vulnerable and users are recommended to upgrade.
Workarounds
Affected embeddings can work around this by specifying a custom implementation of OutputStream which returns a limited value from check_write. Embeddings can also fix this by updating a patch release, too.