Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

Don't panic on empty core rec groups in components (#14976)

Randolf J.209d6c4d2963
diff --git a/crates/environ/src/component/translate.rs b/crates/environ/src/component/translate.rs
index baf49ccc5c..a1b57c07d4 100644
--- a/crates/environ/src/component/translate.rs
+++ b/crates/environ/src/component/translate.rs
@@ -14,8 +14,8 @@ use indexmap::IndexMap;
use std::collections::{HashMap, HashSet};
use std::mem;
use wasmparser::component_types::{
- AliasableResourceId, ComponentCoreModuleTypeId, ComponentDefinedTypeId, ComponentEntityType,
- ComponentFuncTypeId, ComponentInstanceTypeId, ComponentValType,
+ AliasableResourceId, ComponentCoreModuleTypeId, ComponentCoreTypeId, ComponentDefinedTypeId,
+ ComponentEntityType, ComponentFuncTypeId, ComponentInstanceTypeId, ComponentValType,
};
use wasmparser::types::Types;
use wasmparser::{Chunk, ComponentExternName, Encoding, Parser, Payload, Validator};
@@ -903,17 +903,21 @@ impl<'a, 'data> Translator<'a, 'data> {
.core_type_count_in_component();
self.validator.core_type_section(&s)?;
let types = self.validator.types(0).unwrap();
- for ty in s {
- match ty? {
- wasmparser::CoreType::Rec(group) => {
- let id = types.core_type_at_in_component(index).unwrap_sub();
+ let count = types.core_type_count_in_component();
+ while index < count {
+ match types.core_type_at_in_component(index) {
+ // The current type index is always the first type of
+ // its rec group, so intern the group and then skip
+ // past the rest of its types.
+ ComponentCoreTypeId::Sub(id) => {
let group_id = types.rec_group_id_of(id);
self.types
.module_types_builder()
.intern_rec_group(types, group_id)?;
- index += u32::try_from(group.types().len()).unwrap();
+ index +=
+ u32::try_from(types.rec_group_elements(group_id).len()).unwrap();
}
- wasmparser::CoreType::Module(_) => index += 1,
+ ComponentCoreTypeId::Module(_) => index += 1,
}
}
}
diff --git a/tests/misc_testsuite/component-model/empty-rec-groups.wast b/tests/misc_testsuite/component-model/empty-rec-groups.wast
new file mode 100644
index 0000000000..f1a811aec0
--- /dev/null
+++ b/tests/misc_testsuite/component-model/empty-rec-groups.wast
@@ -0,0 +1,6 @@
+;;! gc = true
+
+;; Empty core rec groups define no types.
+(component (core rec))
+(component (core rec) (core type (module)))
+(component (core type (sub (array i8))) (core rec))