Skip to content

Commit a23d4ce

Browse files
authored
[lldb][llvm] Return an error instead of crashing when parsing a line table prologue. (#80769)
We recently ran into some bad DWARF where the `DW_AT_stmt_list` of many compile units was randomly set to invalid values and was causing LLDB to crash due to an assertion about address sizes not matching. Instead of asserting, we should return an appropriate recoverable `llvm::Error`.
1 parent 2e7cacf commit a23d4ce

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,25 @@ Error DWARFDebugLine::Prologue::parse(
389389

390390
if (getVersion() >= 5) {
391391
FormParams.AddrSize = DebugLineData.getU8(Cursor);
392-
assert((!Cursor || DebugLineData.getAddressSize() == 0 ||
393-
DebugLineData.getAddressSize() == getAddressSize()) &&
394-
"Line table header and data extractor disagree");
392+
const uint8_t DataAddrSize = DebugLineData.getAddressSize();
393+
const uint8_t PrologueAddrSize = getAddressSize();
394+
if (Cursor) {
395+
if (DataAddrSize == 0) {
396+
if (PrologueAddrSize != 4 && PrologueAddrSize != 8) {
397+
RecoverableErrorHandler(createStringError(
398+
errc::not_supported,
399+
"parsing line table prologue at offset 0x%8.8" PRIx64
400+
": invalid address size %" PRIu8,
401+
PrologueOffset, PrologueAddrSize));
402+
}
403+
} else if (DataAddrSize != PrologueAddrSize) {
404+
RecoverableErrorHandler(createStringError(
405+
errc::not_supported,
406+
"parsing line table prologue at offset 0x%8.8" PRIx64 ": address "
407+
"size %" PRIu8 " doesn't match architecture address size %" PRIu8,
408+
PrologueOffset, PrologueAddrSize, DataAddrSize));
409+
}
410+
}
395411
SegSelectorSize = DebugLineData.getU8(Cursor);
396412
}
397413

llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,9 @@ TEST_F(DebugLineBasicFixture, ErrorForUnsupportedAddressSizeDefinedInHeader) {
823823
nullptr, RecordRecoverable);
824824
EXPECT_THAT_ERROR(
825825
std::move(Recoverable),
826-
FailedWithMessage("address size 0x09 of DW_LNE_set_address opcode at "
826+
FailedWithMessage("parsing line table prologue at offset 0x00000000: "
827+
"invalid address size 9",
828+
"address size 0x09 of DW_LNE_set_address opcode at "
827829
"offset 0x00000038 is unsupported"));
828830
ASSERT_THAT_EXPECTED(ExpectedLineTable, Succeeded());
829831
ASSERT_EQ((*ExpectedLineTable)->Rows.size(), 3u);

0 commit comments

Comments
 (0)