|
305 | 305 | (export "f" (func $c2 "f")) |
306 | 306 | ) |
307 | 307 | (assert_trap (invoke "f") "unaligned pointer") |
| 308 | + |
| 309 | +;; utf8 -> latin1+utf16 |
| 310 | +;; - first realloc fails to hold latin1 |
| 311 | +;; - second realloc is out of bounds |
| 312 | +(component |
| 313 | + (component $c |
| 314 | + (core module $m |
| 315 | + (global $cnt (mut i32) (i32.const 0)) |
| 316 | + (func (export "") (param i32 i32) |
| 317 | + unreachable |
| 318 | + ) |
| 319 | + (func (export "realloc") (param $old_ptr i32) (param $old_size i32) |
| 320 | + (param $align i32) (param $new_size i32) (result i32) |
| 321 | + (if (i32.ne (local.get $align) (i32.const 2)) (then unreachable)) |
| 322 | + (global.set $cnt (i32.add (global.get $cnt) (i32.const 1))) |
| 323 | + |
| 324 | + ;; first allocation is aligned |
| 325 | + (if (i32.eq (global.get $cnt) (i32.const 1)) |
| 326 | + (then |
| 327 | + (if (i32.ne (local.get $old_ptr) (i32.const 0)) (then unreachable)) |
| 328 | + (if (i32.ne (local.get $old_size) (i32.const 0)) (then unreachable)) |
| 329 | + (if (i32.ne (local.get $new_size) (i32.const 5)) (then unreachable)) |
| 330 | + (return (i32.const 2))) |
| 331 | + ) |
| 332 | + ;; second allocation is out of bounds |
| 333 | + (if (i32.eq (global.get $cnt) (i32.const 2)) |
| 334 | + (then |
| 335 | + (if (i32.ne (local.get $old_ptr) (i32.const 2)) (then unreachable)) |
| 336 | + (if (i32.ne (local.get $old_size) (i32.const 5)) (then unreachable)) |
| 337 | + (if (i32.ne (local.get $new_size) (i32.const 10)) (then unreachable)) |
| 338 | + (return (i32.const -2))) |
| 339 | + ) |
| 340 | + |
| 341 | + unreachable |
| 342 | + ) |
| 343 | + (memory (export "memory") 1) |
| 344 | + ) |
| 345 | + (core instance $m (instantiate $m)) |
| 346 | + (func (export "a") (param "a" string) |
| 347 | + (canon lift |
| 348 | + (core func $m "") |
| 349 | + (realloc (func $m "realloc")) |
| 350 | + (memory $m "memory") |
| 351 | + string-encoding=latin1+utf16) |
| 352 | + ) |
| 353 | + ) |
| 354 | + |
| 355 | + (component $c2 |
| 356 | + (import "a" (func $f (param "a" string))) |
| 357 | + (core module $libc |
| 358 | + (memory (export "memory") 1) |
| 359 | + ;; "Ë┛" in UTF-8 is "\xc3\xab\xe2\x8c\x9b", 5 bytes. |
| 360 | + ;; * First, a 5-byte allocation is made to see if it fits in latin 1. |
| 361 | + ;; * This fails since "┛" does not fit in latin1. The second allocation |
| 362 | + ;; is then out of bounds and should trap |
| 363 | + (data (memory 0) (i32.const 0) "Ë┛") |
| 364 | + ) |
| 365 | + (core instance $libc (instantiate $libc)) |
| 366 | + (core func $f (canon lower (func $f) (memory $libc "memory"))) |
| 367 | + (core module $m |
| 368 | + (import "" "" (func $f (param i32 i32))) |
| 369 | + (func (export "f") (call $f (i32.const 0) (i32.const 5))) |
| 370 | + ) |
| 371 | + (core instance $m (instantiate $m (with "" (instance (export "" (func $f)))))) |
| 372 | + (func (export "f") (canon lift (core func $m "f"))) |
| 373 | + ) |
| 374 | + |
| 375 | + (instance $c (instantiate $c)) |
| 376 | + (instance $c2 (instantiate $c2 (with "a" (func $c "a")))) |
| 377 | + (export "f" (func $c2 "f")) |
| 378 | +) |
| 379 | +(assert_trap (invoke "f") "string content out-of-bounds") |
0 commit comments