Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle non-utf8 hosts in the adapter #8749

Commits on Jun 5, 2024

  1. Handle non-utf8 hosts in the adapter

    This commit is a fix to the WASIp1 adapter for components to better
    handle the case where the host does not use a utf-8 string encoding.
    This is never the case for `wasmtime`-the-crate since it's a Rust-based
    host but this adapter is used outside of Wasmtime in jco, for example,
    where JS is not utf-8-based. When transcoding from utf-16 to utf-8 hosts
    may make an overlarge allocation and then shrink to a smaller
    allocation. This shrinking step has never been supported by the adapter
    and it's always aborted in this case.
    
    Aside: why is this only a problem now? This hasn't been an issue before
    now because jco bindings never actually shrank. In doing so however this
    violated the canonical ABI because allocations are guaranteed to be
    precisely sized. New debug assertions in newer versions of Rust caught
    this mistake. This means that when jco tried to add downsizing of the
    allocation it quickly hit this panic in the adapter.
    
    The fix in this commit is to handle the specific case of shrinking
    memory. The specific fix is to simply ignore the shrinking of memory.
    This is pretty subtle though why it seems to work out well enough for
    now (and it's probably still buggy). For now though this is enough to
    get jco's test suite passing with a shrinking allocation.
    
    Unfortunately I don't know of a way to test this in this repository.
    Wasmtime does not support multiple encodings of host strings, only guest
    strings. This means that there's no wasmtime-based way to pass a
    non-utf-8 string into a guest.
    alexcrichton committed Jun 5, 2024
    Configuration menu
    Copy the full SHA
    c0f5d36 View commit details
    Browse the repository at this point in the history