@@ -763,6 +763,8 @@ bool DwarfFile::DebugAranges::read_set_header(DebugArangesSetHeader& header) {
763
763
return false ;
764
764
}
765
765
766
+ _entry_end = _reader.get_position () + header._unit_length ;
767
+
766
768
if (!_reader.read_word (&header._version ) || header._version != 2 ) {
767
769
// DWARF 4 uses version 2 as specified in Appendix F of the DWARF 4 spec.
768
770
DWARF_LOG_ERROR (" .debug_aranges in unsupported DWARF version %" PRIu16, header._version )
@@ -803,7 +805,7 @@ bool DwarfFile::DebugAranges::read_address_descriptors(const DwarfFile::DebugAra
803
805
found_matching_set = true ;
804
806
return true ;
805
807
}
806
- } while (!is_terminating_entry (descriptor) && _reader.has_bytes_left ());
808
+ } while (!is_terminating_entry (header, descriptor) && _reader.has_bytes_left ());
807
809
808
810
// Set does not match offset_in_library. Continue with next.
809
811
return true ;
@@ -819,8 +821,12 @@ bool DwarfFile::DebugAranges::does_match_offset(const uint32_t offset_in_library
819
821
&& offset_in_library < descriptor.beginning_address + descriptor.range_length ;
820
822
}
821
823
822
- bool DwarfFile::DebugAranges::is_terminating_entry (const AddressDescriptor& descriptor) {
823
- return descriptor.beginning_address == 0 && descriptor.range_length == 0 ;
824
+ bool DwarfFile::DebugAranges::is_terminating_entry (const DwarfFile::DebugAranges::DebugArangesSetHeader& header,
825
+ const AddressDescriptor& descriptor) {
826
+ bool is_terminating = _reader.get_position () >= _entry_end;
827
+ assert (!is_terminating || (descriptor.beginning_address == 0 && descriptor.range_length == 0 ),
828
+ " a terminating entry needs a pair of zero" );
829
+ return is_terminating;
824
830
}
825
831
826
832
// Find the .debug_line offset for the line number program by reading from the .debug_abbrev and .debug_info section.
0 commit comments