GP-0 fix DWARF NPE when .debug_info is 0-padded, DW_FORM_implicit

Fix NPE when null unitHeader (indicating trailing 0-padding was
encountered), and fixed DW_FORM_implicit / DW_FORM_indirect typo in
DWARFAttributeDef read().
This commit is contained in:
dev747368 2024-03-13 18:24:14 +00:00
parent b8f004c792
commit 10c4a59550
2 changed files with 6 additions and 4 deletions

View file

@ -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());

View file

@ -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;