Skip to content

Commit

Permalink
Fix panic with invalid DWARF file indices
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 8, 2024
1 parent 9e22c4e commit 905f04a
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 905f04a

Please sign in to comment.