Handle abbrev entities being out of order.

There are cases where the debug_abbrev entities are not sequential,
for example, in Xamarin system dlls. This change gracefully handles
such a case.

Change-Id: Ib270393d3cf9fd18efd99d15d0fba4f96748188a
Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/3738879
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
This commit is contained in:
Konstantin Mandrika 2022-06-30 14:29:08 -04:00 committed by Joshua Peraza
parent f9fcba812c
commit 3e2a341168

View file

@ -129,10 +129,13 @@ void CompilationUnit::ReadAbbrevs() {
const uint64_t abbrev_length = iter->second.second - header_.abbrev_offset;
#endif
uint64_t highest_number = 0;
while (1) {
CompilationUnit::Abbrev abbrev;
size_t len;
const uint64_t number = reader_->ReadUnsignedLEB128(abbrevptr, &len);
highest_number = std::max(highest_number, number);
if (number == 0)
break;
@ -170,9 +173,17 @@ void CompilationUnit::ReadAbbrevs() {
value);
abbrev.attributes.push_back(abbrev_attr);
}
assert(abbrev.number == abbrevs_->size());
abbrevs_->push_back(abbrev);
}
// Account of cases where entries are out of order.
std::sort(abbrevs_->begin(), abbrevs_->end(),
[](const CompilationUnit::Abbrev& lhs, const CompilationUnit::Abbrev& rhs) {
return lhs.number < rhs.number;
});
// Ensure that there are no missing sections.
assert(abbrevs_->size() == highest_number + 1);
}
// Skips a single DIE's attributes.