Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

Commit

Permalink
handle unknown sections
Browse files Browse the repository at this point in the history
  • Loading branch information
mangas committed May 21, 2022
1 parent 1080066 commit dacfe8d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
Binary file added res/cases/v1/global_section.wasm
Binary file not shown.
8 changes: 1 addition & 7 deletions src/builder/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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() }
}
}
28 changes: 28 additions & 0 deletions src/elements/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
9 changes: 7 additions & 2 deletions src/elements/name_section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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)?;
},
};
}

Expand Down

0 comments on commit dacfe8d

Please sign in to comment.