Ghidra is a software reverse engineering (SRE) framework
GP-4344: Fixing EOFException in CoffLoader due to bad parse of CoffSymbolAuxBeginningOfBlock
Ryan Kurtz6c23c0cb7985
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/coff/CoffSymbolAuxBeginningOfBlock.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/coff/CoffSymbolAuxBeginningOfBlock.javaindex 3858399d9f..0e5508687f 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/coff/CoffSymbolAuxBeginningOfBlock.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/coff/CoffSymbolAuxBeginningOfBlock.java@@ -1,6 +1,5 @@/* ###* IP: GHIDRA- * REVIEWED: YES** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.@@ -16,13 +15,13 @@*/package ghidra.app.util.bin.format.coff;+import java.io.IOException;+import ghidra.app.util.bin.BinaryReader;import ghidra.app.util.bin.StructConverterUtil;import ghidra.program.model.data.DataType;import ghidra.util.exception.DuplicateNameException;-import java.io.IOException;-public class CoffSymbolAuxBeginningOfBlock implements CoffSymbolAux {private byte [] unused1;@@ -34,7 +33,7 @@ public class CoffSymbolAuxBeginningOfBlock implements CoffSymbolAux {CoffSymbolAuxBeginningOfBlock(BinaryReader reader) throws IOException {unused1 = reader.readNextByteArray(4);sourceLineNumber = reader.readNextShort();- unused2 = reader.readNextByteArray(5);+ unused2 = reader.readNextByteArray(6);nextEntryIndex = reader.readNextInt();unused3 = reader.readNextByteArray(2);}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/coff/CoffSymbolSectionNumber.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/coff/CoffSymbolSectionNumber.javaindex 08ad56d9fe..c46134339b 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/coff/CoffSymbolSectionNumber.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/coff/CoffSymbolSectionNumber.java@@ -1,6 +1,5 @@/* ###* IP: GHIDRA- * REVIEWED: YES** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.@@ -22,7 +21,7 @@ public final class CoffSymbolSectionNumber {/** absolute symbols */public final static short N_ABS = -1;/** undefined external symbol */- public final static short N_UNDEf = 0;+ public final static short N_UNDEF = 0;/** .text section symbol */public final static short N_TEXT = 1;/** .data section symbol */diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/CoffLoader.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/CoffLoader.javaindex 1d2659400b..7ee6f016e4 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/CoffLoader.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/CoffLoader.java@@ -242,7 +242,7 @@ public class CoffLoader extends AbstractLibrarySupportLoader {Address address = null;try {short sectionNum = symbol.getSectionNumber();- if (sectionNum == 0) {//external symbols+ if (sectionNum == CoffSymbolSectionNumber.N_UNDEF) {//external symbolsaddress = externalAddress;String name = symbol.getName();Symbol sym = symbolTable.getGlobalSymbol(name, address);@@ -255,13 +255,17 @@ public class CoffLoader extends AbstractLibrarySupportLoader {externalAddress = externalAddress.add(getPointerSizeAligned(externalAddress.getAddressSpace()));}- else if (sectionNum <= -2) {+ else if (sectionNum < CoffSymbolSectionNumber.N_DEBUG) {log.appendMsg("Strange symbol " + symbol + " : " + symbol.getBasicType() +" - from section " + sectionNum);}+ else if (sectionNum == CoffSymbolSectionNumber.N_DEBUG) {+ // skip debug symbols+ continue;+ }else {CoffSectionHeader section = null;- if (sectionNum == -1) { // absolute symbols+ if (sectionNum == CoffSymbolSectionNumber.N_ABS) { // absolute symbols {// usually corresponds to IO or memory registersaddress = CoffSectionHeader.getAddress(program.getLanguage(),symbol.getValue(), program.getLanguage().getDefaultDataSpace());