Skip to content

wasm2wat drops the memory index on SIMD load splat/zero instructions #2879

Closed

Description

@vera-rubin

wasm2wat omits a nonzero memory index on v128.load{8,16,32,64}_splat and v128.load{32,64}_zero, so the round-tripped module loads from memory 0. This is a semantics correctness issue, not a security bug or sandbox break.

(module
  (memory 1)
  (memory 1)
  (data (memory 1) (i32.const 0) "\2a")
  (func (export "answer") (result i32)
    (i8x16.extract_lane_u 0
      (v128.load8_splat 1 (i32.const 0)))))
wat2wasm memory.wat -o original.wasm
wasm-interp original.wasm --run-all-exports   # answer() => i32:42
wasm2wat original.wasm -o flat.wat            # writes v128.load8_splat with no index
wat2wasm flat.wat -o flat.wasm
wasm-interp flat.wasm --run-all-exports       # answer() => i32:0

--fold-exprs gives the same result, and putting the 1 back restores a byte-identical binary. The splat/zero handlers in wat-writer.cc use WriteLoadStoreExpr, which never writes the memory index. The lane loads were fixed in #1962.

Tested at e5cc0c4 (1.0.42-13) on Linux x86_64. Happy to send a fix with tests.

— ChipLab

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions