Skip to content

Commit 95fad44

Browse files
committed
[DebugInfo] Avoid an infinite loop with a truncated pre-v5 .debug_str_offsets.dwo.
dumpStringOffsetsSection() expects the size of a contribution to be correctly aligned. The patch adds the corresponding verifications for pre-v5 cases. Differential Revision: https://reviews.llvm.org/D85739
1 parent 48cd5b7 commit 95fad44

File tree

2 files changed

+77
-6
lines changed

2 files changed

+77
-6
lines changed

llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -995,11 +995,17 @@ DWARFUnit::determineStringOffsetsTableContributionDWO(DWARFDataExtractor & DA) {
995995
// Prior to DWARF v5, we derive the contribution size from the
996996
// index table (in a package file). In a .dwo file it is simply
997997
// the length of the string offsets section.
998-
if (!IndexEntry)
999-
return {Optional<StrOffsetsContributionDescriptor>(
1000-
{0, StringOffsetSection.Data.size(), 4, Header.getFormat()})};
998+
StrOffsetsContributionDescriptor Desc;
1001999
if (C)
1002-
return {Optional<StrOffsetsContributionDescriptor>(
1003-
{C->Offset, C->Length, 4, Header.getFormat()})};
1004-
return None;
1000+
Desc = StrOffsetsContributionDescriptor(C->Offset, C->Length, 4,
1001+
Header.getFormat());
1002+
else if (!IndexEntry && !StringOffsetSection.Data.empty())
1003+
Desc = StrOffsetsContributionDescriptor(0, StringOffsetSection.Data.size(),
1004+
4, Header.getFormat());
1005+
else
1006+
return None;
1007+
auto DescOrError = Desc.validateContributionSize(DA);
1008+
if (!DescOrError)
1009+
return DescOrError.takeError();
1010+
return *DescOrError;
10051011
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
## This tests handling invalid .debug_str_offsets.dwo sections in
2+
## a pre-standard DWO/DWP file.
3+
4+
# RUN: llvm-mc -triple x86_64 %s -filetype=obj -o %t.dwo
5+
# RUN: not llvm-dwarfdump -v %t.dwo 2>&1 | FileCheck %s
6+
7+
# RUN: llvm-mc -triple x86_64 %s -filetype=obj -o %t.dwp --defsym DWP=0
8+
# RUN: not llvm-dwarfdump -v %t.dwp 2>&1 | FileCheck %s
9+
10+
# CHECK: error: invalid reference to or invalid content in .debug_str_offsets[.dwo]: length exceeds section size
11+
12+
.section .debug_abbrev.dwo,"e",@progbits
13+
.LAbbr:
14+
.byte 0x01 # Abbrev code
15+
.byte 0x11 # DW_TAG_compile_unit
16+
.byte 0x00 # DW_CHILDREN_no
17+
.byte 0x00 # EOM(1)
18+
.byte 0x00 # EOM(2)
19+
.byte 0x00 # EOM(3)
20+
.LAbbrEnd:
21+
22+
.section .debug_info.dwo,"e",@progbits
23+
.LCU:
24+
.long .LCUEnd-.LCUVersion
25+
.LCUVersion:
26+
.short 4
27+
.long 0
28+
.byte 8
29+
.uleb128 1
30+
.LCUEnd:
31+
32+
## The section is truncated, i.e. its size is not a multiple of entry size.
33+
.section .debug_str_offsets.dwo,"e",@progbits
34+
.LStrOff:
35+
.byte 0
36+
.LStrOffEnd:
37+
38+
.ifdef DWP
39+
.section .debug_cu_index, "", @progbits
40+
## Header:
41+
.long 2 # Version
42+
.long 3 # Section count
43+
.long 1 # Unit count
44+
.long 2 # Slot count
45+
## Hash Table of Signatures:
46+
.quad 0x1100001122222222 # DWO Id of CU0
47+
.quad 0
48+
## Parallel Table of Indexes:
49+
.long 1
50+
.long 0
51+
## Table of Section Offsets:
52+
## Row 0:
53+
.long 1 # DW_SECT_INFO
54+
.long 3 # DW_SECT_ABBREV
55+
.long 6 # DW_SECT_STR_OFFSETS
56+
## Row 1, offsets of the contribution
57+
.long .LCU-.debug_info.dwo
58+
.long .LAbbr-.debug_abbrev.dwo
59+
.long .LStrOff-.debug_str_offsets.dwo
60+
## Table of Section Sizes:
61+
## Row 1, sizes of the contribution
62+
.long .LCUEnd-.LCU
63+
.long .LAbbrEnd-.LAbbr
64+
.long .LStrOffEnd-.LStrOff
65+
.endif

0 commit comments

Comments
 (0)