-
Notifications
You must be signed in to change notification settings - Fork 57
/
memory_trap.wast
282 lines (272 loc) · 18.5 KB
/
memory_trap.wast
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
(module
(memory 1)
(func $addr_limit (result i32)
(i32.mul (memory.size) (i32.const 0x10000))
)
(func (export "store") (param $i i32) (param $v i32)
(i32.store (i32.add (call $addr_limit) (local.get $i)) (local.get $v))
)
(func (export "load") (param $i i32) (result i32)
(i32.load (i32.add (call $addr_limit) (local.get $i)))
)
(func (export "memory.grow") (param i32) (result i32)
(memory.grow (local.get 0))
)
)
(assert_return (invoke "store" (i32.const -4) (i32.const 42)))
(assert_return (invoke "load" (i32.const -4)) (i32.const 42))
(assert_trap (invoke "store" (i32.const -3) (i32.const 0x12345678)) "out of bounds memory access")
(assert_trap (invoke "load" (i32.const -3)) "out of bounds memory access")
(assert_trap (invoke "store" (i32.const -2) (i32.const 13)) "out of bounds memory access")
(assert_trap (invoke "load" (i32.const -2)) "out of bounds memory access")
(assert_trap (invoke "store" (i32.const -1) (i32.const 13)) "out of bounds memory access")
(assert_trap (invoke "load" (i32.const -1)) "out of bounds memory access")
(assert_trap (invoke "store" (i32.const 0) (i32.const 13)) "out of bounds memory access")
(assert_trap (invoke "load" (i32.const 0)) "out of bounds memory access")
(assert_trap (invoke "store" (i32.const 0x80000000) (i32.const 13)) "out of bounds memory access")
(assert_trap (invoke "load" (i32.const 0x80000000)) "out of bounds memory access")
(assert_return (invoke "memory.grow" (i32.const 0x10001)) (i32.const -1))
(module
(memory 1)
(data (i32.const 0) "abcdefgh")
(data (i32.const 0xfff8) "abcdefgh")
(func (export "i32.load") (param $a i32) (result i32)
(i32.load (local.get $a))
)
(func (export "i64.load") (param $a i32) (result i64)
(i64.load (local.get $a))
)
(func (export "f32.load") (param $a i32) (result f32)
(f32.load (local.get $a))
)
(func (export "f64.load") (param $a i32) (result f64)
(f64.load (local.get $a))
)
(func (export "i32.load8_s") (param $a i32) (result i32)
(i32.load8_s (local.get $a))
)
(func (export "i32.load8_u") (param $a i32) (result i32)
(i32.load8_u (local.get $a))
)
(func (export "i32.load16_s") (param $a i32) (result i32)
(i32.load16_s (local.get $a))
)
(func (export "i32.load16_u") (param $a i32) (result i32)
(i32.load16_u (local.get $a))
)
(func (export "i64.load8_s") (param $a i32) (result i64)
(i64.load8_s (local.get $a))
)
(func (export "i64.load8_u") (param $a i32) (result i64)
(i64.load8_u (local.get $a))
)
(func (export "i64.load16_s") (param $a i32) (result i64)
(i64.load16_s (local.get $a))
)
(func (export "i64.load16_u") (param $a i32) (result i64)
(i64.load16_u (local.get $a))
)
(func (export "i64.load32_s") (param $a i32) (result i64)
(i64.load32_s (local.get $a))
)
(func (export "i64.load32_u") (param $a i32) (result i64)
(i64.load32_u (local.get $a))
)
(func (export "i32.store") (param $a i32) (param $v i32)
(i32.store (local.get $a) (local.get $v))
)
(func (export "i64.store") (param $a i32) (param $v i64)
(i64.store (local.get $a) (local.get $v))
)
(func (export "f32.store") (param $a i32) (param $v f32)
(f32.store (local.get $a) (local.get $v))
)
(func (export "f64.store") (param $a i32) (param $v f64)
(f64.store (local.get $a) (local.get $v))
)
(func (export "i32.store8") (param $a i32) (param $v i32)
(i32.store8 (local.get $a) (local.get $v))
)
(func (export "i32.store16") (param $a i32) (param $v i32)
(i32.store16 (local.get $a) (local.get $v))
)
(func (export "i64.store8") (param $a i32) (param $v i64)
(i64.store8 (local.get $a) (local.get $v))
)
(func (export "i64.store16") (param $a i32) (param $v i64)
(i64.store16 (local.get $a) (local.get $v))
)
(func (export "i64.store32") (param $a i32) (param $v i64)
(i64.store32 (local.get $a) (local.get $v))
)
)
(assert_trap (invoke "i32.store" (i32.const 0x10000) (i32.const 0)) "out of bounds memory access")
(assert_trap (invoke "i32.store" (i32.const 0xffff) (i32.const 0)) "out of bounds memory access")
(assert_trap (invoke "i32.store" (i32.const 0xfffe) (i32.const 0)) "out of bounds memory access")
(assert_trap (invoke "i32.store" (i32.const 0xfffd) (i32.const 0)) "out of bounds memory access")
(assert_trap (invoke "i32.store" (i32.const -1) (i32.const 0)) "out of bounds memory access")
(assert_trap (invoke "i32.store" (i32.const -2) (i32.const 0)) "out of bounds memory access")
(assert_trap (invoke "i32.store" (i32.const -3) (i32.const 0)) "out of bounds memory access")
(assert_trap (invoke "i32.store" (i32.const -4) (i32.const 0)) "out of bounds memory access")
(assert_trap (invoke "i64.store" (i32.const 0x10000) (i64.const 0)) "out of bounds memory access")
(assert_trap (invoke "i64.store" (i32.const 0xffff) (i64.const 0)) "out of bounds memory access")
(assert_trap (invoke "i64.store" (i32.const 0xfffe) (i64.const 0)) "out of bounds memory access")
(assert_trap (invoke "i64.store" (i32.const 0xfffd) (i64.const 0)) "out of bounds memory access")
(assert_trap (invoke "i64.store" (i32.const 0xfffc) (i64.const 0)) "out of bounds memory access")
(assert_trap (invoke "i64.store" (i32.const 0xfffb) (i64.const 0)) "out of bounds memory access")
(assert_trap (invoke "i64.store" (i32.const 0xfffa) (i64.const 0)) "out of bounds memory access")
(assert_trap (invoke "i64.store" (i32.const 0xfff9) (i64.const 0)) "out of bounds memory access")
(assert_trap (invoke "i64.store" (i32.const -1) (i64.const 0)) "out of bounds memory access")
(assert_trap (invoke "i64.store" (i32.const -2) (i64.const 0)) "out of bounds memory access")
(assert_trap (invoke "i64.store" (i32.const -3) (i64.const 0)) "out of bounds memory access")
(assert_trap (invoke "i64.store" (i32.const -4) (i64.const 0)) "out of bounds memory access")
(assert_trap (invoke "i64.store" (i32.const -5) (i64.const 0)) "out of bounds memory access")
(assert_trap (invoke "i64.store" (i32.const -6) (i64.const 0)) "out of bounds memory access")
(assert_trap (invoke "i64.store" (i32.const -7) (i64.const 0)) "out of bounds memory access")
(assert_trap (invoke "i64.store" (i32.const -8) (i64.const 0)) "out of bounds memory access")
(assert_trap (invoke "f32.store" (i32.const 0x10000) (f32.const 0)) "out of bounds memory access")
(assert_trap (invoke "f32.store" (i32.const 0xffff) (f32.const 0)) "out of bounds memory access")
(assert_trap (invoke "f32.store" (i32.const 0xfffe) (f32.const 0)) "out of bounds memory access")
(assert_trap (invoke "f32.store" (i32.const 0xfffd) (f32.const 0)) "out of bounds memory access")
(assert_trap (invoke "f32.store" (i32.const -1) (f32.const 0)) "out of bounds memory access")
(assert_trap (invoke "f32.store" (i32.const -2) (f32.const 0)) "out of bounds memory access")
(assert_trap (invoke "f32.store" (i32.const -3) (f32.const 0)) "out of bounds memory access")
(assert_trap (invoke "f32.store" (i32.const -4) (f32.const 0)) "out of bounds memory access")
(assert_trap (invoke "f64.store" (i32.const 0x10000) (f64.const 0)) "out of bounds memory access")
(assert_trap (invoke "f64.store" (i32.const 0xffff) (f64.const 0)) "out of bounds memory access")
(assert_trap (invoke "f64.store" (i32.const 0xfffe) (f64.const 0)) "out of bounds memory access")
(assert_trap (invoke "f64.store" (i32.const 0xfffd) (f64.const 0)) "out of bounds memory access")
(assert_trap (invoke "f64.store" (i32.const 0xfffc) (f64.const 0)) "out of bounds memory access")
(assert_trap (invoke "f64.store" (i32.const 0xfffb) (f64.const 0)) "out of bounds memory access")
(assert_trap (invoke "f64.store" (i32.const 0xfffa) (f64.const 0)) "out of bounds memory access")
(assert_trap (invoke "f64.store" (i32.const 0xfff9) (f64.const 0)) "out of bounds memory access")
(assert_trap (invoke "f64.store" (i32.const -1) (f64.const 0)) "out of bounds memory access")
(assert_trap (invoke "f64.store" (i32.const -2) (f64.const 0)) "out of bounds memory access")
(assert_trap (invoke "f64.store" (i32.const -3) (f64.const 0)) "out of bounds memory access")
(assert_trap (invoke "f64.store" (i32.const -4) (f64.const 0)) "out of bounds memory access")
(assert_trap (invoke "f64.store" (i32.const -5) (f64.const 0)) "out of bounds memory access")
(assert_trap (invoke "f64.store" (i32.const -6) (f64.const 0)) "out of bounds memory access")
(assert_trap (invoke "f64.store" (i32.const -7) (f64.const 0)) "out of bounds memory access")
(assert_trap (invoke "f64.store" (i32.const -8) (f64.const 0)) "out of bounds memory access")
(assert_trap (invoke "i32.store8" (i32.const 0x10000) (i32.const 0)) "out of bounds memory access")
(assert_trap (invoke "i32.store8" (i32.const -1) (i32.const 0)) "out of bounds memory access")
(assert_trap (invoke "i32.store16" (i32.const 0x10000) (i32.const 0)) "out of bounds memory access")
(assert_trap (invoke "i32.store16" (i32.const 0xffff) (i32.const 0)) "out of bounds memory access")
(assert_trap (invoke "i32.store16" (i32.const -1) (i32.const 0)) "out of bounds memory access")
(assert_trap (invoke "i32.store16" (i32.const -2) (i32.const 0)) "out of bounds memory access")
(assert_trap (invoke "i64.store8" (i32.const 0x10000) (i64.const 0)) "out of bounds memory access")
(assert_trap (invoke "i64.store8" (i32.const -1) (i64.const 0)) "out of bounds memory access")
(assert_trap (invoke "i64.store16" (i32.const 0x10000) (i64.const 0)) "out of bounds memory access")
(assert_trap (invoke "i64.store16" (i32.const 0xffff) (i64.const 0)) "out of bounds memory access")
(assert_trap (invoke "i64.store16" (i32.const -1) (i64.const 0)) "out of bounds memory access")
(assert_trap (invoke "i64.store16" (i32.const -2) (i64.const 0)) "out of bounds memory access")
(assert_trap (invoke "i64.store32" (i32.const 0x10000) (i64.const 0)) "out of bounds memory access")
(assert_trap (invoke "i64.store32" (i32.const 0xffff) (i64.const 0)) "out of bounds memory access")
(assert_trap (invoke "i64.store32" (i32.const 0xfffe) (i64.const 0)) "out of bounds memory access")
(assert_trap (invoke "i64.store32" (i32.const 0xfffd) (i64.const 0)) "out of bounds memory access")
(assert_trap (invoke "i64.store32" (i32.const -1) (i64.const 0)) "out of bounds memory access")
(assert_trap (invoke "i64.store32" (i32.const -2) (i64.const 0)) "out of bounds memory access")
(assert_trap (invoke "i64.store32" (i32.const -3) (i64.const 0)) "out of bounds memory access")
(assert_trap (invoke "i64.store32" (i32.const -4) (i64.const 0)) "out of bounds memory access")
(assert_trap (invoke "i32.load" (i32.const 0x10000)) "out of bounds memory access")
(assert_trap (invoke "i32.load" (i32.const 0xffff)) "out of bounds memory access")
(assert_trap (invoke "i32.load" (i32.const 0xfffe)) "out of bounds memory access")
(assert_trap (invoke "i32.load" (i32.const 0xfffd)) "out of bounds memory access")
(assert_trap (invoke "i32.load" (i32.const -1)) "out of bounds memory access")
(assert_trap (invoke "i32.load" (i32.const -2)) "out of bounds memory access")
(assert_trap (invoke "i32.load" (i32.const -3)) "out of bounds memory access")
(assert_trap (invoke "i32.load" (i32.const -4)) "out of bounds memory access")
(assert_trap (invoke "i64.load" (i32.const 0x10000)) "out of bounds memory access")
(assert_trap (invoke "i64.load" (i32.const 0xffff)) "out of bounds memory access")
(assert_trap (invoke "i64.load" (i32.const 0xfffe)) "out of bounds memory access")
(assert_trap (invoke "i64.load" (i32.const 0xfffd)) "out of bounds memory access")
(assert_trap (invoke "i64.load" (i32.const 0xfffc)) "out of bounds memory access")
(assert_trap (invoke "i64.load" (i32.const 0xfffb)) "out of bounds memory access")
(assert_trap (invoke "i64.load" (i32.const 0xfffa)) "out of bounds memory access")
(assert_trap (invoke "i64.load" (i32.const 0xfff9)) "out of bounds memory access")
(assert_trap (invoke "i64.load" (i32.const -1)) "out of bounds memory access")
(assert_trap (invoke "i64.load" (i32.const -2)) "out of bounds memory access")
(assert_trap (invoke "i64.load" (i32.const -3)) "out of bounds memory access")
(assert_trap (invoke "i64.load" (i32.const -4)) "out of bounds memory access")
(assert_trap (invoke "i64.load" (i32.const -5)) "out of bounds memory access")
(assert_trap (invoke "i64.load" (i32.const -6)) "out of bounds memory access")
(assert_trap (invoke "i64.load" (i32.const -7)) "out of bounds memory access")
(assert_trap (invoke "i64.load" (i32.const -8)) "out of bounds memory access")
(assert_trap (invoke "f32.load" (i32.const 0x10000)) "out of bounds memory access")
(assert_trap (invoke "f32.load" (i32.const 0xffff)) "out of bounds memory access")
(assert_trap (invoke "f32.load" (i32.const 0xfffe)) "out of bounds memory access")
(assert_trap (invoke "f32.load" (i32.const 0xfffd)) "out of bounds memory access")
(assert_trap (invoke "f32.load" (i32.const -1)) "out of bounds memory access")
(assert_trap (invoke "f32.load" (i32.const -2)) "out of bounds memory access")
(assert_trap (invoke "f32.load" (i32.const -3)) "out of bounds memory access")
(assert_trap (invoke "f32.load" (i32.const -4)) "out of bounds memory access")
(assert_trap (invoke "f64.load" (i32.const 0x10000)) "out of bounds memory access")
(assert_trap (invoke "f64.load" (i32.const 0xffff)) "out of bounds memory access")
(assert_trap (invoke "f64.load" (i32.const 0xfffe)) "out of bounds memory access")
(assert_trap (invoke "f64.load" (i32.const 0xfffd)) "out of bounds memory access")
(assert_trap (invoke "f64.load" (i32.const 0xfffc)) "out of bounds memory access")
(assert_trap (invoke "f64.load" (i32.const 0xfffb)) "out of bounds memory access")
(assert_trap (invoke "f64.load" (i32.const 0xfffa)) "out of bounds memory access")
(assert_trap (invoke "f64.load" (i32.const 0xfff9)) "out of bounds memory access")
(assert_trap (invoke "f64.load" (i32.const -1)) "out of bounds memory access")
(assert_trap (invoke "f64.load" (i32.const -2)) "out of bounds memory access")
(assert_trap (invoke "f64.load" (i32.const -3)) "out of bounds memory access")
(assert_trap (invoke "f64.load" (i32.const -4)) "out of bounds memory access")
(assert_trap (invoke "f64.load" (i32.const -5)) "out of bounds memory access")
(assert_trap (invoke "f64.load" (i32.const -6)) "out of bounds memory access")
(assert_trap (invoke "f64.load" (i32.const -7)) "out of bounds memory access")
(assert_trap (invoke "f64.load" (i32.const -8)) "out of bounds memory access")
(assert_trap (invoke "i32.load8_s" (i32.const 0x10000)) "out of bounds memory access")
(assert_trap (invoke "i32.load8_s" (i32.const -1)) "out of bounds memory access")
(assert_trap (invoke "i32.load8_u" (i32.const 0x10000)) "out of bounds memory access")
(assert_trap (invoke "i32.load8_u" (i32.const -1)) "out of bounds memory access")
(assert_trap (invoke "i32.load16_s" (i32.const 0x10000)) "out of bounds memory access")
(assert_trap (invoke "i32.load16_s" (i32.const 0xffff)) "out of bounds memory access")
(assert_trap (invoke "i32.load16_s" (i32.const -1)) "out of bounds memory access")
(assert_trap (invoke "i32.load16_s" (i32.const -2)) "out of bounds memory access")
(assert_trap (invoke "i32.load16_u" (i32.const 0x10000)) "out of bounds memory access")
(assert_trap (invoke "i32.load16_u" (i32.const 0xffff)) "out of bounds memory access")
(assert_trap (invoke "i32.load16_u" (i32.const -1)) "out of bounds memory access")
(assert_trap (invoke "i32.load16_u" (i32.const -2)) "out of bounds memory access")
(assert_trap (invoke "i64.load8_s" (i32.const 0x10000)) "out of bounds memory access")
(assert_trap (invoke "i64.load8_s" (i32.const -1)) "out of bounds memory access")
(assert_trap (invoke "i64.load8_u" (i32.const 0x10000)) "out of bounds memory access")
(assert_trap (invoke "i64.load8_u" (i32.const -1)) "out of bounds memory access")
(assert_trap (invoke "i64.load16_s" (i32.const 0x10000)) "out of bounds memory access")
(assert_trap (invoke "i64.load16_s" (i32.const 0xffff)) "out of bounds memory access")
(assert_trap (invoke "i64.load16_s" (i32.const -1)) "out of bounds memory access")
(assert_trap (invoke "i64.load16_s" (i32.const -2)) "out of bounds memory access")
(assert_trap (invoke "i64.load16_u" (i32.const 0x10000)) "out of bounds memory access")
(assert_trap (invoke "i64.load16_u" (i32.const 0xffff)) "out of bounds memory access")
(assert_trap (invoke "i64.load16_u" (i32.const -1)) "out of bounds memory access")
(assert_trap (invoke "i64.load16_u" (i32.const -2)) "out of bounds memory access")
(assert_trap (invoke "i64.load32_s" (i32.const 0x10000)) "out of bounds memory access")
(assert_trap (invoke "i64.load32_s" (i32.const 0xffff)) "out of bounds memory access")
(assert_trap (invoke "i64.load32_s" (i32.const 0xfffe)) "out of bounds memory access")
(assert_trap (invoke "i64.load32_s" (i32.const 0xfffd)) "out of bounds memory access")
(assert_trap (invoke "i64.load32_s" (i32.const -1)) "out of bounds memory access")
(assert_trap (invoke "i64.load32_s" (i32.const -2)) "out of bounds memory access")
(assert_trap (invoke "i64.load32_s" (i32.const -3)) "out of bounds memory access")
(assert_trap (invoke "i64.load32_s" (i32.const -4)) "out of bounds memory access")
(assert_trap (invoke "i64.load32_u" (i32.const 0x10000)) "out of bounds memory access")
(assert_trap (invoke "i64.load32_u" (i32.const 0xffff)) "out of bounds memory access")
(assert_trap (invoke "i64.load32_u" (i32.const 0xfffe)) "out of bounds memory access")
(assert_trap (invoke "i64.load32_u" (i32.const 0xfffd)) "out of bounds memory access")
(assert_trap (invoke "i64.load32_u" (i32.const -1)) "out of bounds memory access")
(assert_trap (invoke "i64.load32_u" (i32.const -2)) "out of bounds memory access")
(assert_trap (invoke "i64.load32_u" (i32.const -3)) "out of bounds memory access")
(assert_trap (invoke "i64.load32_u" (i32.const -4)) "out of bounds memory access")
;; No memory was changed
(assert_return (invoke "i64.load" (i32.const 0xfff8)) (i64.const 0x6867666564636261))
(assert_return (invoke "i64.load" (i32.const 0)) (i64.const 0x6867666564636261))
;; Check that out of bounds store do not store partial data.
;; Zero last 8 bytes.
(assert_return (invoke "i64.store" (i32.const 0xfff8) (i64.const 0)))
(assert_trap (invoke "i32.store" (i32.const 0xfffd) (i32.const 0x12345678)) "out of bounds memory access")
(assert_return (invoke "i32.load" (i32.const 0xfffc)) (i32.const 0))
(assert_trap (invoke "i64.store" (i32.const 0xfff9) (i64.const 0x1234567890abcdef)) "out of bounds memory access")
(assert_return (invoke "i64.load" (i32.const 0xfff8)) (i64.const 0))
(assert_trap (invoke "f32.store" (i32.const 0xfffd) (f32.const 0x12345678)) "out of bounds memory access")
(assert_return (invoke "f32.load" (i32.const 0xfffc)) (f32.const 0))
(assert_trap (invoke "f64.store" (i32.const 0xfff9) (f64.const 0x1234567890abcdef)) "out of bounds memory access")
(assert_return (invoke "f64.load" (i32.const 0xfff8)) (f64.const 0))