Skip to content

null strings cause crash #1734

Closed
Closed
@surma

Description

@surma

I think this was introduced with #1682. That PR seems to indicate that null strings should be handled as the empty string, but they can cause a memory access out of bounds error.

export function prefix(s: string): string {
  return "prefix:" + s;
}
<!DOCTYPE html>
<script>
  async function main() {
    const { instance } = await WebAssembly.instantiateStreaming(
      fetch("lol.wasm"),
      {
        env: {
          abort() {
            throw Error("ARGH");
          },
        },
      }
    );
    const strPtr = 0; // !! Invalid string pointer
    instance.exports.prefix(strPtr);
  }
  main();
</script>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions