From e532563c671573754d1d8254ae1e983c297aeaea Mon Sep 17 00:00:00 2001 From: Benjamin Romano Date: Tue, 7 May 2024 02:42:45 -0700 Subject: [PATCH] Avoid infinite recursion on indirect self-references (#836) --- CHANGELOG.md | 1 + symbolic-debuginfo/src/dwarf.rs | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43fe3826..340aeb6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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** diff --git a/symbolic-debuginfo/src/dwarf.rs b/symbolic-debuginfo/src/dwarf.rs index ab8912f9..2e41bc82 100644 --- a/symbolic-debuginfo/src/dwarf.rs +++ b/symbolic-debuginfo/src/dwarf.rs @@ -419,6 +419,7 @@ impl<'d, 'a> UnitRef<'d, 'a> { entry: &Die<'d, '_>, language: Language, bcsymbolmap: Option<&'d BcSymbolMap<'d>>, + prior_offset: Option, ) -> Result>, DwarfError> { let mut attrs = entry.attrs(); let mut fallback_name = None; @@ -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) } @@ -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> { self.inner - .resolve_function_name(entry, self.language, self.bcsymbolmap) + .resolve_function_name(entry, self.language, self.bcsymbolmap, None) .ok() .flatten() }