File: partial-init-memory-segment.wast

package info (click to toggle)
rust-wasmtime 28.0.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 54,116 kB
  • sloc: ansic: 4,071; sh: 567; javascript: 548; cpp: 280; asm: 175; ml: 96; makefile: 55
file content (35 lines) | stat: -rw-r--r-- 1,189 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
(module $m
  (memory (export "mem") 1)

  (func (export "load") (param i32) (result i32)
    local.get 0
    i32.load8_u))

(register "m" $m)

(assert_trap
  (module
    (memory (import "m" "mem") 1)

    ;; This is in bounds, and should get written to the memory.
    (data (i32.const 0) "abc")

    ;; Partially out of bounds. None of these bytes should get written, and
    ;; instantiation should trap.
    (data (i32.const 65530) "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz")
  )
  "out of bounds"
)

;; The first data segment got written.
(assert_return (invoke $m "load" (i32.const 0)) (i32.const 97))
(assert_return (invoke $m "load" (i32.const 1)) (i32.const 98))
(assert_return (invoke $m "load" (i32.const 2)) (i32.const 99))

;; The second did not get partially written.
(assert_return (invoke $m "load" (i32.const 65530)) (i32.const 0))
(assert_return (invoke $m "load" (i32.const 65531)) (i32.const 0))
(assert_return (invoke $m "load" (i32.const 65532)) (i32.const 0))
(assert_return (invoke $m "load" (i32.const 65533)) (i32.const 0))
(assert_return (invoke $m "load" (i32.const 65534)) (i32.const 0))
(assert_return (invoke $m "load" (i32.const 65535)) (i32.const 0))