Commit b1c7bfe6 authored by James Henderson's avatar James Henderson
Browse files

[DebugInfo] Reject line tables of version > 5

If a debug line section with version of greater than 5 is encountered,
prior to this change the parser would accept it and treat it as version
5. This might work to some extent, but then it might not at all, as it
really depends on the format of the unspecified future version, which
will be different (otherwise there would be no point in changing the
version number). Any information we could provide has a good chance of
being invalid, so we should just refuse to parse such tables.

Reviewed by: dblaikie, MaskRay

Differential Revision: https://reviews.llvm.org/D74204
parent cd37f0ad
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -327,7 +327,7 @@ Error DWARFDebugLine::Prologue::parse(
        PrologueOffset, TotalLength);
  }
  FormParams.Version = DebugLineData.getU16(OffsetPtr);
  if (getVersion() < 2)
  if (getVersion() < 2 || getVersion() > 5)
    // Treat this error as unrecoverable - we cannot be sure what any of
    // the data represents including the length field, so cannot skip it or make
    // any reasonable assumptions.
+15 −0
Original line number Diff line number Diff line
@@ -354,6 +354,21 @@ TEST_F(DebugLineBasicFixture, ErrorForLowVersion) {
      "0x01");
}

TEST_F(DebugLineBasicFixture, ErrorForHighVersion) {
  if (!setupGenerator())
    return;

  LineTable &LT = Gen->addLineTable();
  LT.setCustomPrologue(
      {{LineTable::Half, LineTable::Long}, {6, LineTable::Half}});

  generate();

  checkGetOrParseLineTableEmitsFatalError(
      "parsing line table prologue at offset 0x00000000 found unsupported "
      "version 0x06");
}

TEST_F(DebugLineBasicFixture, ErrorForInvalidV5IncludeDirTable) {
  if (!setupGenerator(5))
    return;