diff --git a/src/BinaryParsers/ElfBinary/Dwarf/DwarfEnums.cs b/src/BinaryParsers/ElfBinary/Dwarf/DwarfEnums.cs index 6367e571c..642c87716 100644 --- a/src/BinaryParsers/ElfBinary/Dwarf/DwarfEnums.cs +++ b/src/BinaryParsers/ElfBinary/Dwarf/DwarfEnums.cs @@ -415,6 +415,9 @@ public enum DwarfAttribute /// public enum DwarfLineNumberStandardOpcode { + // Extended opcodes (0) + // Standard opcodes (1 to 12) + // Special opcodes (13 or greater) Extended = 0, Copy = 0x01, AdvancePc = 0x02, diff --git a/src/BinaryParsers/ElfBinary/Dwarf/DwarfLineNumberProgram.cs b/src/BinaryParsers/ElfBinary/Dwarf/DwarfLineNumberProgram.cs index f981e33fa..a52d1cd2b 100644 --- a/src/BinaryParsers/ElfBinary/Dwarf/DwarfLineNumberProgram.cs +++ b/src/BinaryParsers/ElfBinary/Dwarf/DwarfLineNumberProgram.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -193,6 +192,11 @@ private static List ReadData(DwarfMemoryReader debugLine, byte lineRange = debugLine.ReadByte(); byte operationCodeBase = debugLine.ReadByte(); + if (operationCodeBase <= 0) + { + return new List(); + } + // Read operation code lengths uint[] operationCodeLengths = new uint[operationCodeBase]; @@ -312,7 +316,11 @@ private static List ReadData(DwarfMemoryReader debugLine, break; case DwarfLineNumberStandardOpcode.SetFile: - state.File = files[(int)debugLine.LEB128() - 1]; + int index = (int)debugLine.LEB128() - 1; + if (index >= 0 && index < files.Count) + { + state.File = files[index]; + } break; case DwarfLineNumberStandardOpcode.SetColumn: @@ -348,12 +356,9 @@ private static List ReadData(DwarfMemoryReader debugLine, state.Isa = debugLine.LEB128(); break; - case (DwarfLineNumberStandardOpcode)13: - // when reading some dwarf debugline data, get OpCode 13 which is not in dwarf official document - break; - default: - throw new Exception($"Unsupported DwarfLineNumberStandardOpcode: {(DwarfLineNumberStandardOpcode)operationCode}"); + // Special opcodes(13 or greater) + break; } } } diff --git a/src/ReleaseHistory.md b/src/ReleaseHistory.md index fcb183943..a7b0effd2 100644 --- a/src/ReleaseHistory.md +++ b/src/ReleaseHistory.md @@ -2,6 +2,7 @@ ## Unreleased +* BUGFIX: Fix opcode handling when reading DWARF line number programs. [#482](https://github.com/microsoft/binskim/pull/482) * BUGFIX: Fix exception `System.ArgumentException` when checking file format. [#481](https://github.com/microsoft/binskim/pull/481) * BUGFIX: Change compiler report rule to report all modules in file. [#476](https://github.com/microsoft/binskim/pull/476) * FEATURE: Add dialects to the reporting rules. [#475](https://github.com/microsoft/binskim/pull/475)