Skip to content

Commit

Permalink
Avoid infinite recursion on indirect self-references (#836)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminRomano authored May 7, 2024
1 parent 2b0af54 commit e532563
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
**Internal**

- Update tokio to latest version ([#833](https://github.com/getsentry/symbolic/pull/833))
- Fix infinite recursion caused by indirect self-references when resolving function names ([#836](https://github.com/getsentry/symbolic/pull/836))

**Fixes**

Expand Down
18 changes: 16 additions & 2 deletions symbolic-debuginfo/src/dwarf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ impl<'d, 'a> UnitRef<'d, 'a> {
entry: &Die<'d, '_>,
language: Language,
bcsymbolmap: Option<&'d BcSymbolMap<'d>>,
prior_offset: Option<UnitOffset>,
) -> Result<Option<Name<'d>>, DwarfError> {
let mut attrs = entry.attrs();
let mut fallback_name = None;
Expand Down Expand Up @@ -452,8 +453,21 @@ impl<'d, 'a> UnitRef<'d, 'a> {

if let Some(attr) = reference_target {
return self.resolve_reference(attr, |ref_unit, ref_entry| {
// Self-references may have a layer of indircetion. Avoid infinite recursion
// in this scenario.
if let Some(prior) = prior_offset {
if self.offset() == ref_unit.offset() && prior == ref_entry.offset() {
return Ok(None);
}
}

if self.offset() != ref_unit.offset() || entry.offset() != ref_entry.offset() {
ref_unit.resolve_function_name(ref_entry, language, bcsymbolmap)
ref_unit.resolve_function_name(
ref_entry,
language,
bcsymbolmap,
Some(entry.offset()),
)
} else {
Ok(None)
}
Expand Down Expand Up @@ -714,7 +728,7 @@ impl<'d, 'a> DwarfUnit<'d, 'a> {
/// Resolves the name of a function from DWARF debug information.
fn resolve_dwarf_name(&self, entry: &Die<'d, '_>) -> Option<Name<'d>> {
self.inner
.resolve_function_name(entry, self.language, self.bcsymbolmap)
.resolve_function_name(entry, self.language, self.bcsymbolmap, None)
.ok()
.flatten()
}
Expand Down

0 comments on commit e532563

Please sign in to comment.