Skip to content

array.new_data / array.new_elem trap on a zero-length access of a dropped segment (should succeed) #657

Description

@jasisz

A passive data / element segment that has been data.drop / elem.drop'd has length 0. An array.new_data / array.new_elem with offset 0 and size 0 is in bounds (0 + 0 <= 0) and must produce an empty array, not trap. Wizard traps MEMORY_OOB.

Repro

(module
  (data $d "ab")
  (type $a (array (mut i8)))
  (func (export "f") (result i32)
    (data.drop $d)
    (drop (array.new_data $a $d (i32.const 0) (i32.const 0)))   ;; in bounds: a zero-length array
    (i32.const 33)))

wasm-tools, wasmtime, WasmEdge and V8 accept and return 33; Wizard traps MEMORY_OOB.

The parallel array.new_elem from a dropped passive element segment behaves the same. A non-dropped size-0 array.new_data succeeds on Wizard too, so it is specifically the dropped-segment + size-0 combination — the dropped segment should be treated as a zero-length segment, leaving a size-0 access in bounds.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions