github.com/tetratelabs/wazero@v1.7.3-0.20240513003603-48f702e154b5/internal/integration_test/spectest/v2/testdata/data.wast (about) 1 ;; Test the data section 2 3 ;; Syntax 4 5 (module 6 (memory $m 1) 7 (data (i32.const 0)) 8 (data (i32.const 1) "a" "" "bcd") 9 (data (offset (i32.const 0))) 10 (data (offset (i32.const 0)) "" "a" "bc" "") 11 (data (memory 0) (i32.const 0)) 12 (data (memory 0x0) (i32.const 1) "a" "" "bcd") 13 (data (memory 0x000) (offset (i32.const 0))) 14 (data (memory 0) (offset (i32.const 0)) "" "a" "bc" "") 15 (data (memory $m) (i32.const 0)) 16 (data (memory $m) (i32.const 1) "a" "" "bcd") 17 (data (memory $m) (offset (i32.const 0))) 18 (data (memory $m) (offset (i32.const 0)) "" "a" "bc" "") 19 (data $d1 (i32.const 0)) 20 (data $d2 (i32.const 1) "a" "" "bcd") 21 (data $d3 (offset (i32.const 0))) 22 (data $d4 (offset (i32.const 0)) "" "a" "bc" "") 23 (data $d5 (memory 0) (i32.const 0)) 24 (data $d6 (memory 0x0) (i32.const 1) "a" "" "bcd") 25 (data $d7 (memory 0x000) (offset (i32.const 0))) 26 (data $d8 (memory 0) (offset (i32.const 0)) "" "a" "bc" "") 27 (data $d9 (memory $m) (i32.const 0)) 28 (data $d10 (memory $m) (i32.const 1) "a" "" "bcd") 29 (data $d11 (memory $m) (offset (i32.const 0))) 30 (data $d12 (memory $m) (offset (i32.const 0)) "" "a" "bc" "") 31 ) 32 33 ;; Basic use 34 35 (module 36 (memory 1) 37 (data (i32.const 0) "a") 38 ) 39 (module 40 (import "spectest" "memory" (memory 1)) 41 (data (i32.const 0) "a") 42 ) 43 44 (module 45 (memory 1) 46 (data (i32.const 0) "a") 47 (data (i32.const 3) "b") 48 (data (i32.const 100) "cde") 49 (data (i32.const 5) "x") 50 (data (i32.const 3) "c") 51 ) 52 (module 53 (import "spectest" "memory" (memory 1)) 54 (data (i32.const 0) "a") 55 (data (i32.const 1) "b") 56 (data (i32.const 2) "cde") 57 (data (i32.const 3) "f") 58 (data (i32.const 2) "g") 59 (data (i32.const 1) "h") 60 ) 61 62 (module 63 (global (import "spectest" "global_i32") i32) 64 (memory 1) 65 (data (global.get 0) "a") 66 ) 67 (module 68 (global (import "spectest" "global_i32") i32) 69 (import "spectest" "memory" (memory 1)) 70 (data (global.get 0) "a") 71 ) 72 73 (module 74 (global $g (import "spectest" "global_i32") i32) 75 (memory 1) 76 (data (global.get $g) "a") 77 ) 78 (module 79 (global $g (import "spectest" "global_i32") i32) 80 (import "spectest" "memory" (memory 1)) 81 (data (global.get $g) "a") 82 ) 83 84 (assert_invalid 85 (module (memory 1) (global i32 (i32.const 0)) (data (global.get 0) "a")) 86 "unknown global" 87 ) 88 (assert_invalid 89 (module (memory 1) (global $g i32 (i32.const 0)) (data (global.get $g) "a")) 90 "unknown global" 91 ) 92 93 94 ;; Corner cases 95 96 (module 97 (memory 1) 98 (data (i32.const 0) "a") 99 (data (i32.const 0xffff) "b") 100 ) 101 (module 102 (import "spectest" "memory" (memory 1)) 103 (data (i32.const 0) "a") 104 (data (i32.const 0xffff) "b") 105 ) 106 107 (module 108 (memory 2) 109 (data (i32.const 0x1_ffff) "a") 110 ) 111 112 (module 113 (memory 0) 114 (data (i32.const 0)) 115 ) 116 (module 117 (import "spectest" "memory" (memory 0)) 118 (data (i32.const 0)) 119 ) 120 121 (module 122 (memory 0 0) 123 (data (i32.const 0)) 124 ) 125 126 (module 127 (memory 1) 128 (data (i32.const 0x1_0000) "") 129 ) 130 131 (module 132 (memory 0) 133 (data (i32.const 0) "" "") 134 ) 135 (module 136 (import "spectest" "memory" (memory 0)) 137 (data (i32.const 0) "" "") 138 ) 139 140 (module 141 (memory 0 0) 142 (data (i32.const 0) "" "") 143 ) 144 145 (module 146 (import "spectest" "memory" (memory 0)) 147 (data (i32.const 0) "a") 148 ) 149 150 (module 151 (import "spectest" "memory" (memory 0 3)) 152 (data (i32.const 0) "a") 153 ) 154 155 (module 156 (global (import "spectest" "global_i32") i32) 157 (import "spectest" "memory" (memory 0)) 158 (data (global.get 0) "a") 159 ) 160 161 (module 162 (global (import "spectest" "global_i32") i32) 163 (import "spectest" "memory" (memory 0 3)) 164 (data (global.get 0) "a") 165 ) 166 167 (module 168 (import "spectest" "memory" (memory 0)) 169 (data (i32.const 1) "a") 170 ) 171 172 (module 173 (import "spectest" "memory" (memory 0 3)) 174 (data (i32.const 1) "a") 175 ) 176 177 ;; Invalid bounds for data 178 179 (assert_trap 180 (module 181 (memory 0) 182 (data (i32.const 0) "a") 183 ) 184 "out of bounds memory access" 185 ) 186 187 (assert_trap 188 (module 189 (memory 0 0) 190 (data (i32.const 0) "a") 191 ) 192 "out of bounds memory access" 193 ) 194 195 (assert_trap 196 (module 197 (memory 0 1) 198 (data (i32.const 0) "a") 199 ) 200 "out of bounds memory access" 201 ) 202 (assert_trap 203 (module 204 (memory 0) 205 (data (i32.const 1)) 206 ) 207 "out of bounds memory access" 208 ) 209 (assert_trap 210 (module 211 (memory 0 1) 212 (data (i32.const 1)) 213 ) 214 "out of bounds memory access" 215 ) 216 217 ;; This seems to cause a time-out on Travis. 218 (;assert_unlinkable 219 (module 220 (memory 0x10000) 221 (data (i32.const 0xffffffff) "ab") 222 ) 223 "" ;; either out of memory or out of bounds 224 ;) 225 226 (assert_trap 227 (module 228 (global (import "spectest" "global_i32") i32) 229 (memory 0) 230 (data (global.get 0) "a") 231 ) 232 "out of bounds memory access" 233 ) 234 235 (assert_trap 236 (module 237 (memory 1 2) 238 (data (i32.const 0x1_0000) "a") 239 ) 240 "out of bounds memory access" 241 ) 242 (assert_trap 243 (module 244 (import "spectest" "memory" (memory 1)) 245 (data (i32.const 0x1_0000) "a") 246 ) 247 "out of bounds memory access" 248 ) 249 250 (assert_trap 251 (module 252 (memory 2) 253 (data (i32.const 0x2_0000) "a") 254 ) 255 "out of bounds memory access" 256 ) 257 258 (assert_trap 259 (module 260 (memory 2 3) 261 (data (i32.const 0x2_0000) "a") 262 ) 263 "out of bounds memory access" 264 ) 265 266 (assert_trap 267 (module 268 (memory 1) 269 (data (i32.const -1) "a") 270 ) 271 "out of bounds memory access" 272 ) 273 (assert_trap 274 (module 275 (import "spectest" "memory" (memory 1)) 276 (data (i32.const -1) "a") 277 ) 278 "out of bounds memory access" 279 ) 280 281 (assert_trap 282 (module 283 (memory 2) 284 (data (i32.const -100) "a") 285 ) 286 "out of bounds memory access" 287 ) 288 (assert_trap 289 (module 290 (import "spectest" "memory" (memory 1)) 291 (data (i32.const -100) "a") 292 ) 293 "out of bounds memory access" 294 ) 295 296 ;; Data without memory 297 298 (assert_invalid 299 (module 300 (data (i32.const 0) "") 301 ) 302 "unknown memory" 303 ) 304 305 ;; Data segment with memory index 1 (only memory 0 available) 306 (assert_invalid 307 (module binary 308 "\00asm" "\01\00\00\00" 309 "\05\03\01" ;; memory section 310 "\00\00" ;; memory 0 311 "\0b\07\01" ;; data section 312 "\02\01\41\00\0b" ;; active data segment 0 for memory 1 313 "\00" ;; empty vec(byte) 314 ) 315 "unknown memory 1" 316 ) 317 318 ;; Data segment with memory index 0 (no memory section) 319 (assert_invalid 320 (module binary 321 "\00asm" "\01\00\00\00" 322 "\0b\06\01" ;; data section 323 "\00\41\00\0b" ;; active data segment 0 for memory 0 324 "\00" ;; empty vec(byte) 325 ) 326 "unknown memory 0" 327 ) 328 329 ;; Data segment with memory index 1 (no memory section) 330 (assert_invalid 331 (module binary 332 "\00asm" "\01\00\00\00" 333 "\0b\07\01" ;; data section 334 "\02\01\41\00\0b" ;; active data segment 0 for memory 1 335 "\00" ;; empty vec(byte) 336 ) 337 "unknown memory 1" 338 ) 339 340 ;; Data segment with memory index 1 and vec(byte) as above, 341 ;; only memory 0 available. 342 (assert_invalid 343 (module binary 344 "\00asm" "\01\00\00\00" 345 "\05\03\01" ;; memory section 346 "\00\00" ;; memory 0 347 "\0b\45\01" ;; data section 348 "\02" ;; active segment 349 "\01" ;; memory index 350 "\41\00\0b" ;; offset constant expression 351 "\3e" ;; vec(byte) length 352 "\00\01\02\03\04\05\06\07\08\09\0a\0b\0c\0d\0e\0f" 353 "\10\11\12\13\14\15\16\17\18\19\1a\1b\1c\1d\1e\1f" 354 "\20\21\22\23\24\25\26\27\28\29\2a\2b\2c\2d\2e\2f" 355 "\30\31\32\33\34\35\36\37\38\39\3a\3b\3c\3d" 356 ) 357 "unknown memory 1" 358 ) 359 360 ;; Data segment with memory index 1 and specially crafted vec(byte) after. 361 ;; This is to detect incorrect validation where memory index is interpreted 362 ;; as a flag followed by "\41" interpreted as the size of vec(byte) 363 ;; with the expected number of bytes following. 364 (assert_invalid 365 (module binary 366 "\00asm" "\01\00\00\00" 367 "\0b\45\01" ;; data section 368 "\02" ;; active segment 369 "\01" ;; memory index 370 "\41\00\0b" ;; offset constant expression 371 "\3e" ;; vec(byte) length 372 "\00\01\02\03\04\05\06\07\08\09\0a\0b\0c\0d\0e\0f" 373 "\10\11\12\13\14\15\16\17\18\19\1a\1b\1c\1d\1e\1f" 374 "\20\21\22\23\24\25\26\27\28\29\2a\2b\2c\2d\2e\2f" 375 "\30\31\32\33\34\35\36\37\38\39\3a\3b\3c\3d" 376 ) 377 "unknown memory 1" 378 ) 379 380 381 ;; Invalid offsets 382 383 (assert_invalid 384 (module 385 (memory 1) 386 (data (i64.const 0)) 387 ) 388 "type mismatch" 389 ) 390 391 (assert_invalid 392 (module 393 (memory 1) 394 (data (ref.null func)) 395 ) 396 "type mismatch" 397 ) 398 399 (assert_invalid 400 (module 401 (memory 1) 402 (data (offset (;empty instruction sequence;))) 403 ) 404 "type mismatch" 405 ) 406 407 (assert_invalid 408 (module 409 (memory 1) 410 (data (offset (i32.const 0) (i32.const 0))) 411 ) 412 "type mismatch" 413 ) 414 415 (assert_invalid 416 (module 417 (global (import "test" "global-i32") i32) 418 (memory 1) 419 (data (offset (global.get 0) (global.get 0))) 420 ) 421 "type mismatch" 422 ) 423 424 (assert_invalid 425 (module 426 (global (import "test" "global-i32") i32) 427 (memory 1) 428 (data (offset (global.get 0) (i32.const 0))) 429 ) 430 "type mismatch" 431 ) 432 433 (assert_invalid 434 (module 435 (memory 1) 436 (data (i32.ctz (i32.const 0))) 437 ) 438 "constant expression required" 439 ) 440 441 (assert_invalid 442 (module 443 (memory 1) 444 (data (nop)) 445 ) 446 "constant expression required" 447 ) 448 449 (assert_invalid 450 (module 451 (memory 1) 452 (data (offset (nop) (i32.const 0))) 453 ) 454 "constant expression required" 455 ) 456 457 (assert_invalid 458 (module 459 (memory 1) 460 (data (offset (i32.const 0) (nop))) 461 ) 462 "constant expression required" 463 ) 464 465 (assert_invalid 466 (module 467 (global $g (import "test" "g") (mut i32)) 468 (memory 1) 469 (data (global.get $g)) 470 ) 471 "constant expression required" 472 ) 473 474 (assert_invalid 475 (module 476 (memory 1) 477 (data (global.get 0)) 478 ) 479 "unknown global 0" 480 ) 481 482 (assert_invalid 483 (module 484 (global (import "test" "global-i32") i32) 485 (memory 1) 486 (data (global.get 1)) 487 ) 488 "unknown global 1" 489 ) 490 491 (assert_invalid 492 (module 493 (global (import "test" "global-mut-i32") (mut i32)) 494 (memory 1) 495 (data (global.get 0)) 496 ) 497 "constant expression required" 498 )