Skip to content

Commit

Permalink
Fix panic with invalid DWARF file indices (#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 (#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 #8884
Closes #8904
  • Loading branch information
alexcrichton authored Jul 8, 2024
1 parent 9e22c4e commit e4fe818
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 e4fe818

Please sign in to comment.