Skip to content

Commit

Permalink
Fix panic with invalid DWARF file indices (bytecodealliance#8913)
Browse files Browse the repository at this point in the history
I'm not entirely sure what causes this but Wasmtime shouldn't panic with
invalid DWARF. In general (bytecodealliance#5537) Wasmtime's support for DWARF needs to
be rewritten, but in the meantime let's play whack-a-mole with panics
and try to paper over issues.

Closes bytecodealliance#8884
Closes bytecodealliance#8904
  • Loading branch information
alexcrichton committed Jul 9, 2024
1 parent 4fa5ab3 commit 747e695
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion crates/cranelift/src/debug/transform/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,15 @@ where
..
} = file_context
{
write::AttributeValue::FileIndex(Some(file_map[(i - file_index_base) as usize]))
let index = usize::try_from(i - file_index_base)
.ok()
.and_then(|i| file_map.get(i).copied());
match index {
Some(index) => write::AttributeValue::FileIndex(Some(index)),
// This was seen to be invalid in #8884 and #8904 so
// ignore this seemingly invalid DWARF from LLVM
None => continue,
}
} else {
return Err(TransformError("unexpected file index attribute").into());
}
Expand Down

0 comments on commit 747e695

Please sign in to comment.