github.com/tetratelabs/wazero@v1.7.3-0.20240513003603-48f702e154b5/internal/integration_test/spectest/v2/testdata/memory_trap.wast (about)

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