| 1 |
use std::borrow::Cow; |
| 2 |
use wasm_encoder::*; |
| 3 |
|
| 4 |
#[test] |
| 5 |
fn big_type_indices() { |
| 6 |
const N: u32 = 100_000; |
| 7 |
let mut module = Module::new(); |
| 8 |
let mut types = TypeSection::new(); |
| 9 |
for _ in 0..N { |
| 10 |
types.ty().function([], []); |
| 11 |
} |
| 12 |
module.section(&types); |
| 13 |
let mut funcs = FunctionSection::new(); |
| 14 |
funcs.function(N - 1); |
| 15 |
module.section(&funcs); |
| 16 |
|
| 17 |
let mut elems = ElementSection::new(); |
| 18 |
elems.declared(Elements::Functions(Cow::Borrowed(&[0]))); |
| 19 |
module.section(&elems); |
| 20 |
|
| 21 |
let mut code = CodeSection::new(); |
| 22 |
let mut body = Function::new([]); |
| 23 |
body.instructions().ref_func(0); |
| 24 |
body.instructions().drop(); |
| 25 |
body.instructions().end(); |
| 26 |
code.function(&body); |
| 27 |
module.section(&code); |
| 28 |
|
| 29 |
let wasm = module.finish(); |
| 30 |
|
| 31 |
wasmparser::Validator::default() |
| 32 |
.validate_all(&wasm) |
| 33 |
.unwrap(); |
| 34 |
} |