From 415b54ab8cebeb317ab7e0dbb14cd55229eb5a59 Mon Sep 17 00:00:00 2001 From: Joshua Peraza Date: Thu, 8 Jul 2021 15:13:33 -0700 Subject: [PATCH] Account for string offsets table header size Section 7.26 of the DWARF 5 spec describes a header of either 8 or 16 bytes before the offsets begin. Bug: b/187205051 Change-Id: I1ba01008dcd7a533f59d3865762ca09b9d43032b Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/3016609 Reviewed-by: Sterling Augustine --- src/common/dwarf/dwarf2reader.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/common/dwarf/dwarf2reader.cc b/src/common/dwarf/dwarf2reader.cc index b130ed13..5850fb7c 100644 --- a/src/common/dwarf/dwarf2reader.cc +++ b/src/common/dwarf/dwarf2reader.cc @@ -456,8 +456,14 @@ uint64_t CompilationUnit::Start() { void CompilationUnit::ProcessFormStringIndex( uint64_t dieoffset, enum DwarfAttribute attr, enum DwarfForm form, uint64_t str_index) { + const size_t kStringOffsetsTableHeaderSize = + reader_->OffsetSize() == 8 ? 16 : 8; + const uint8_t* str_offsets_table_after_header = str_offsets_base_ ? + str_offsets_buffer_ + str_offsets_base_ : + str_offsets_buffer_ + kStringOffsetsTableHeaderSize; const uint8_t* offset_ptr = - str_offsets_buffer_ + str_offsets_base_ + str_index * reader_->OffsetSize(); + str_offsets_table_after_header + str_index * reader_->OffsetSize(); + const uint64_t offset = reader_->ReadOffset(offset_ptr); if (offset >= string_buffer_length_) { return;