Skip to content

Commit

Permalink
read/wasm: Ignore errors when loading name subsection (#408)
Browse files Browse the repository at this point in the history
The version of `wasmparser` currently in use does not
support extended name sections and will return an error
when such an unknown subsection is encountered.
This commit is a quick work-around until `wasmparser`
is updated to the most recent version - which is a
rather big undertaking unfortunately.

One downside of this work-around is that ill-formed
name subsections (e.g. for function names) are
silently ignored.
  • Loading branch information
lwagner94 authored Dec 15, 2021
1 parent 74e27e4 commit e45a3d1
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions src/read/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,25 +254,30 @@ impl<'data, R: ReadRef<'data>> WasmFile<'data, R> {
.get_name_section_reader()
.read_error("Couldn't read header of the name section")?
{
let name =
match name.read_error("Couldn't read header of a name subsection")? {
wp::Name::Function(name) => name,
_ => continue,
};
let mut name_map = name
.get_map()
.read_error("Couldn't read header of the function name subsection")?;
for _ in 0..name_map.get_count() {
let naming = name_map
.read()
.read_error("Couldn't read a function name")?;
if let Some(local_index) =
naming.index.checked_sub(imported_funcs_count)
{
if let LocalFunctionKind::Local { symbol_id } =
local_func_kinds[local_index as usize]
// TODO: Right now, ill-formed name subsections
// are silently ignored in order to maintain
// compatibility with extended name sections, which
// are not yet supported by the version of
// `wasmparser` currently used.
// A better fix would be to update `wasmparser` to
// the newest version, but this requires
// a major rewrite of this file.
if let Ok(wp::Name::Function(name)) = name {
let mut name_map = name.get_map().read_error(
"Couldn't read header of the function name subsection",
)?;
for _ in 0..name_map.get_count() {
let naming = name_map
.read()
.read_error("Couldn't read a function name")?;
if let Some(local_index) =
naming.index.checked_sub(imported_funcs_count)
{
file.symbols[symbol_id as usize].name = naming.name;
if let LocalFunctionKind::Local { symbol_id } =
local_func_kinds[local_index as usize]
{
file.symbols[symbol_id as usize].name = naming.name;
}
}
}
}
Expand Down

0 comments on commit e45a3d1

Please sign in to comment.