Ghidra is a software reverse engineering (SRE) framework
GP-0 fix DWARF NPE when .debug_info is 0-padded, DW_FORM_implicit
dev74736810c4a5955026
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/DWARFProgram.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/DWARFProgram.javaindex 1527933c22..4a93dfb5d1 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/DWARFProgram.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/DWARFProgram.java@@ -316,10 +316,11 @@ public class DWARFProgram implements Closeable {DWARFUnitHeader unitHeader =DWARFUnitHeader.read(this, debugInfoBR, debugAbbrBR, compUnits.size(), monitor);- if (unitHeader != null) {- debugInfoBR.setPointerIndex(unitHeader.getEndOffset());+ if (unitHeader == null) {+ break;}+ debugInfoBR.setPointerIndex(unitHeader.getEndOffset());if (unitHeader instanceof DWARFCompilationUnit cu) {compUnits.add(cu);importSummary.dwarfVers.add((int) cu.getDWARFVersion());diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/attribs/DWARFAttributeDef.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/attribs/DWARFAttributeDef.javaindex 56fb596bd9..c01b925f07 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/attribs/DWARFAttributeDef.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/attribs/DWARFAttributeDef.java@@ -69,8 +69,9 @@ public class DWARFAttributeDef<E extends Enum<E>> {E e = mapper.apply(attributeId);// NOTE: implicit value is a space saving hack built into DWARF. It adds an extra- // field in the attributespec that needs to be read.- long implicitValue = form == DWARFForm.DW_FORM_indirect // read leb128 if present+ // field in the attributespec that needs to be read now in the .debug_abbr. This is+ // different than DW_FORM_indirect, which is read from the DIE in .debug_info+ long implicitValue = form == DWARFForm.DW_FORM_implicit_const // read leb128 if present? reader.readNext(LEB128::signed): 0;