diff --git a/res/cases/v1/global_section.wasm b/res/cases/v1/global_section.wasm new file mode 100644 index 000000000..5eac6e80a Binary files /dev/null and b/res/cases/v1/global_section.wasm differ diff --git a/src/builder/table.rs b/src/builder/table.rs index 6bfcb40c8..54d2c7270 100644 --- a/src/builder/table.rs +++ b/src/builder/table.rs @@ -3,7 +3,7 @@ use crate::elements; use alloc::vec::Vec; /// Table definition -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Default)] pub struct TableDefinition { /// Minimum length pub min: u32, @@ -79,9 +79,3 @@ where self.callback.invoke(self.table) } } - -impl Default for TableDefinition { - fn default() -> Self { - TableDefinition { min: 0, max: None, elements: Vec::new() } - } -} diff --git a/src/elements/module.rs b/src/elements/module.rs index 96efa1a90..8cabd3feb 100644 --- a/src/elements/module.rs +++ b/src/elements/module.rs @@ -904,6 +904,34 @@ mod integration_tests { assert!(found_section, "Name section should be present in dedicated example"); } + #[test] + fn names_with_global_section() { + let module = deserialize_file("./res/cases/v1/global_section.wasm") + .expect("Should be deserialized") + .parse_names() + .expect("Names to be parsed"); + + let mut found_section = false; + for section in module.sections() { + if let Section::Name(ref name_section) = *section { + let function_name_subsection = + name_section.functions().expect("function_name_subsection should be present"); + assert_eq!( + function_name_subsection.names().get(0).expect("Should be entry #0"), + "~lib/builtins/abort" + ); + assert_eq!( + function_name_subsection.names().get(11).expect("Should be entry #0"), + "~lib/typedarray/Uint8Array#__set" + ); + + found_section = true; + } + } + + assert!(found_section, "Name section should be present in dedicated example"); + } + // This test fixture has FLAG_SHARED so it depends on atomics feature. #[test] fn shared_memory_flag() { diff --git a/src/elements/name_section.rs b/src/elements/name_section.rs index 7b005bd5d..f1f340155 100644 --- a/src/elements/name_section.rs +++ b/src/elements/name_section.rs @@ -73,7 +73,7 @@ impl NameSection { while let Ok(raw_subsection_type) = VarUint7::deserialize(rdr) { let subsection_type = raw_subsection_type.into(); // deserialize the section size - VarUint32::deserialize(rdr)?; + let size: usize = VarUint32::deserialize(rdr)?.into(); match subsection_type { NAME_TYPE_MODULE => { @@ -97,7 +97,12 @@ impl NameSection { local_names = Some(LocalNameSubsection::deserialize(module, rdr)?); }, - _ => return Err(Error::UnknownNameSubsectionType(subsection_type)), + _ => { + // Consume the entire subsection size and drop it. This allows other sections to still be + // consumed if there are any. + let mut buf = vec![0; size]; + rdr.read(&mut buf)?; + }, }; }