Skip to content

Commit dcdfb0e

Browse files
authored
Use different limits for items in components (#1390)
Right now the validation limit for the number of memories or tables in a component is quite small, only 100. This is the core wasm limit which is intended to limit the number of definitions in core wasm, but in a component items taking up the index space are just references, not definitions. That means they don't need to have similarly small limits and can instead be much larger. Closes #1389
1 parent 61607a4 commit dcdfb0e

File tree

5 files changed

+853
-5
lines changed

5 files changed

+853
-5
lines changed

crates/wasm-compose/tests/compositions/not-instance-import/composed.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
(with "a" (func 0))
1919
)
2020
)
21-
)
21+
)

crates/wasmparser/src/limits.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,8 @@ pub const MAX_WASM_MODULES: usize = 1_000;
5757
pub const MAX_WASM_COMPONENTS: usize = 1_000;
5858
pub const MAX_WASM_INSTANCES: usize = 1_000;
5959
pub const MAX_WASM_VALUES: usize = 1_000;
60+
61+
/// Core items in components such as globals/memories/tables don't actually
62+
/// create new definitions but are instead just aliases to preexisting items.
63+
/// This means they have a different limit than the core wasm based limits.
64+
pub const MAX_CORE_INDEX_SPACE_ITEMS: usize = 1_000_000;

crates/wasmparser/src/validator/component.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2303,14 +2303,20 @@ impl ComponentState {
23032303
push_module_export!(EntityType::Func, core_funcs, "function")
23042304
}
23052305
ExternalKind::Table => {
2306-
check_max(self.core_tables.len(), 1, MAX_WASM_TABLES, "tables", offset)?;
2306+
check_max(
2307+
self.core_tables.len(),
2308+
1,
2309+
MAX_CORE_INDEX_SPACE_ITEMS,
2310+
"tables",
2311+
offset,
2312+
)?;
23072313
push_module_export!(EntityType::Table, core_tables, "table")
23082314
}
23092315
ExternalKind::Memory => {
23102316
check_max(
23112317
self.core_memories.len(),
23122318
1,
2313-
MAX_WASM_MEMORIES,
2319+
MAX_CORE_INDEX_SPACE_ITEMS,
23142320
"memories",
23152321
offset,
23162322
)?;
@@ -2320,14 +2326,20 @@ impl ComponentState {
23202326
check_max(
23212327
self.core_globals.len(),
23222328
1,
2323-
MAX_WASM_GLOBALS,
2329+
MAX_CORE_INDEX_SPACE_ITEMS,
23242330
"globals",
23252331
offset,
23262332
)?;
23272333
push_module_export!(EntityType::Global, core_globals, "global")
23282334
}
23292335
ExternalKind::Tag => {
2330-
check_max(self.core_tags.len(), 1, MAX_WASM_TAGS, "tags", offset)?;
2336+
check_max(
2337+
self.core_tags.len(),
2338+
1,
2339+
MAX_CORE_INDEX_SPACE_ITEMS,
2340+
"tags",
2341+
offset,
2342+
)?;
23312343
push_module_export!(EntityType::Tag, core_tags, "tag")
23322344
}
23332345
}

0 commit comments

Comments
 (0)