| 1876 | |
| 1877 | #[test] |
| 1878 | fn string_list_oob() -> Result<()> { |
| 1879 | let component = format!( |
| 1880 | r#"(component |
| 1881 | (core module $m |
| 1882 | (memory (export "memory") 1) |
| 1883 | (func (export "ret-list") (result i32) |
| 1884 | (local $base i32) |
| 1885 | |
| 1886 | ;; Allocate space for the return |
| 1887 | (local.set $base |
| 1888 | (call $realloc |
| 1889 | (i32.const 0) |
| 1890 | (i32.const 0) |
| 1891 | (i32.const 4) |
| 1892 | (i32.const 8))) |
| 1893 | |
| 1894 | (i32.store offset=0 |
| 1895 | (local.get $base) |
| 1896 | (i32.const 100000)) |
| 1897 | (i32.store offset=4 |
| 1898 | (local.get $base) |
| 1899 | (i32.const 1)) |
| 1900 | |
| 1901 | (local.get $base) |
| 1902 | ) |
| 1903 | |
| 1904 | {REALLOC_AND_FREE} |
| 1905 | ) |
| 1906 | (core instance $i (instantiate $m)) |
| 1907 | |
| 1908 | (func (export "ret-list-u8") (result (list u8)) |
| 1909 | (canon lift (core func $i "ret-list") |
| 1910 | (memory $i "memory") |
| 1911 | (realloc (func $i "realloc")) |
| 1912 | ) |
| 1913 | ) |
| 1914 | (func (export "ret-string") (result string) |
| 1915 | (canon lift (core func $i "ret-list") |
| 1916 | (memory $i "memory") |
| 1917 | (realloc (func $i "realloc")) |
| 1918 | ) |
| 1919 | ) |
| 1920 | )"# |
| 1921 | ); |
| 1922 | |
| 1923 | let engine = super::engine(); |
| 1924 | let component = Component::new(&engine, component)?; |
| 1925 | let mut store = Store::new(&engine, ()); |
| 1926 | let ret_list_u8 = Linker::new(&engine) |
| 1927 | .instantiate(&mut store, &component)? |
| 1928 | .get_typed_func::<(), (WasmList<u8>,)>(&mut store, "ret-list-u8")?; |
| 1929 | let ret_string = Linker::new(&engine) |
| 1930 | .instantiate(&mut store, &component)? |
| 1931 | .get_typed_func::<(), (WasmStr,)>(&mut store, "ret-string")?; |
| 1932 | |
| 1933 | let err = ret_list_u8.call(&mut store, ()).err().unwrap(); |
| 1934 | assert!(err.to_string().contains("out of bounds"), "{}", err); |
| 1935 | |