Skip to content

Commit

Permalink
wasmparser: Fix subtyping depth indexing
Browse files Browse the repository at this point in the history
fix: #1967

This patch addresses an issue in subtyping depth checking
where `set_subtyping_depth` indexes the depth by `CoreTypeId`,
but `get_subtyping_depth` accesses it using `CoreTypeId#index` (`u32`).
This leads to "IndexMap: index out of bounds" error when validating
WasmGC components with subtypes.
  • Loading branch information
tanishiking committed Jan 8, 2025
1 parent 46881c9 commit d017108
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/wasmparser/src/validator/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ impl TypeList {
let depth = self
.core_type_to_depth
.as_ref()
.expect("cannot get subtype depth from a committed list")[id.index()];
.expect("cannot get subtype depth from a committed list")[&id];
debug_assert!(usize::from(depth) <= crate::limits::MAX_WASM_SUBTYPING_DEPTH);
depth
}
Expand Down
9 changes: 9 additions & 0 deletions tests/local/component-model/gc.wast
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,12 @@
))
)
"sub type cannot have a final super type")

(component
(type $t (resource (rep i32)))
(core func (canon resource.drop $t))
(core module
(type $t1 (sub (func)))
(type (sub $t1 (func)))
)
)
6 changes: 6 additions & 0 deletions tests/snapshots/local/component-model/gc.wast.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@
"filename": "gc.11.wasm",
"module_type": "binary",
"text": "sub type cannot have a final super type"
},
{
"type": "module",
"line": 128,
"filename": "gc.12.wasm",
"module_type": "binary"
}
]
}
8 changes: 8 additions & 0 deletions tests/snapshots/local/component-model/gc.wast/12.print
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(component
(type $t (;0;) (resource (rep i32)))
(core func (;0;) (canon resource.drop $t))
(core module (;0;)
(type $t1 (;0;) (sub (func)))
(type (;1;) (sub $t1 (func)))
)
)

0 comments on commit d017108

Please sign in to comment.