Skip to content

Commit

Permalink
Use different limits for items in components
Browse files Browse the repository at this point in the history
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 bytecodealliance#1389
  • Loading branch information
alexcrichton committed Jan 28, 2024
1 parent d15fda3 commit b2a25b4
Show file tree
Hide file tree
Showing 5 changed files with 853 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
(with "a" (func 0))
)
)
)
)
5 changes: 5 additions & 0 deletions crates/wasmparser/src/limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,8 @@ pub const MAX_WASM_MODULES: usize = 1_000;
pub const MAX_WASM_COMPONENTS: usize = 1_000;
pub const MAX_WASM_INSTANCES: usize = 1_000;
pub const MAX_WASM_VALUES: usize = 1_000;

/// Core items in components such as globals/memories/tables don't actually
/// create new definitions but are instead just aliases to preexisting items.
/// This means they have a different limit than the core wasm based limits.
pub const MAX_CORE_INDEX_SPACE_ITEMS: usize = 1_000_000;
20 changes: 16 additions & 4 deletions crates/wasmparser/src/validator/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2303,14 +2303,20 @@ impl ComponentState {
push_module_export!(EntityType::Func, core_funcs, "function")
}
ExternalKind::Table => {
check_max(self.core_tables.len(), 1, MAX_WASM_TABLES, "tables", offset)?;
check_max(
self.core_tables.len(),
1,
MAX_CORE_INDEX_SPACE_ITEMS,
"tables",
offset,
)?;
push_module_export!(EntityType::Table, core_tables, "table")
}
ExternalKind::Memory => {
check_max(
self.core_memories.len(),
1,
MAX_WASM_MEMORIES,
MAX_CORE_INDEX_SPACE_ITEMS,
"memories",
offset,
)?;
Expand All @@ -2320,14 +2326,20 @@ impl ComponentState {
check_max(
self.core_globals.len(),
1,
MAX_WASM_GLOBALS,
MAX_CORE_INDEX_SPACE_ITEMS,
"globals",
offset,
)?;
push_module_export!(EntityType::Global, core_globals, "global")
}
ExternalKind::Tag => {
check_max(self.core_tags.len(), 1, MAX_WASM_TAGS, "tags", offset)?;
check_max(
self.core_tags.len(),
1,
MAX_CORE_INDEX_SPACE_ITEMS,
"tags",
offset,
)?;
push_module_export!(EntityType::Tag, core_tags, "tag")
}
}
Expand Down
Loading

0 comments on commit b2a25b4

Please sign in to comment.