Ghidra is a software reverse engineering (SRE) framework
GP-3314 corrected zero-length DataComponent issue
ghidra1b8fed4fd807b
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/code/DataComponent.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/code/DataComponent.javaindex c2cb05c840..b9d783126b 100644--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/code/DataComponent.java+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/code/DataComponent.java@@ -40,7 +40,9 @@ class DataComponent extends DataDB {private int[] path;/**- * Constructs a new DataComponent+ * Constructs a new {@link DataComponent} for a {@link DataTypeComponent}.+ * NOTE: a zero-length component will be forced to have a length of 1-byte.+ * This can result in what would appear to be overlapping components with the same overset.* @param codeMgr the code manager.* @param componentCache data component cache* @param address the address of the data component@@ -57,29 +59,31 @@ class DataComponent extends DataDB {this.component = component;this.level = parent.level + 1;this.offset = component.getOffset();- this.length = component.getLength();+ length = component.getLength();+ if (length == 0) {+ length = 1; // zero-length components must be forced to have a length of 1+ }}/**- * Constructs a new array DataComponent.+ * Constructs a new {@link DataComponent} for an {@link Array} element.* @param codeMgr the code manager.* @param componentCache data component cache* @param address the address of the data component* @param addr the convert address long value* @param parent the DataDB object that contains this component.* @param array the array containing this component.- * @param ordinal the ordinal for this component.- * @param offset the offset of this component within its parent.- * @param length the length of this component.+ * @param ordinal the array index for this component.*/DataComponent(CodeManager codeMgr, DBObjectCache<DataDB> componentCache, Address address,- long addr, DataDB parent, Array array, int ordinal, int offset, int length) {+ long addr, DataDB parent, Array array, int ordinal) {super(codeMgr, componentCache, ordinal, address, addr, array.getDataType());+ int elementLength = array.getElementLength();this.indexInParent = ordinal;this.parent = parent;- this.offset = offset;+ this.offset = ordinal * elementLength;this.level = parent.level + 1;- this.length = length;+ this.length = elementLength;}@Override@@ -102,6 +106,9 @@ class DataComponent extends DataDB {dataType = c.getDataType();offset = component.getOffset();length = component.getLength();+ if (length == 0) {+ length = 1; // zero-length components must be forced to have a length of 1+ }}else if (pdt instanceof Array) {Array a = (Array) pdt;diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/code/DataDB.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/code/DataDB.javaindex 2dfe56cdec..270e02355b 100644--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/code/DataDB.java+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/code/DataDB.java@@ -230,19 +230,16 @@ class DataDB extends CodeUnitDB implements Data {if (baseDataType instanceof Array) {Array array = (Array) baseDataType;- int elementLength = array.getElementLength();- Address componentAddr = address.add(index * elementLength);+ Address componentAddr = address.add(index * array.getElementLength());return new DataComponent(codeMgr, componentCache, componentAddr,- addressMap.getKey(componentAddr, false), this, array, index,- index * elementLength, elementLength);+ addressMap.getKey(componentAddr, false), this, array, index);}if (baseDataType instanceof Composite) {- Composite struct = (Composite) baseDataType;- DataTypeComponent dtc = struct.getComponent(index);+ Composite composite = (Composite) baseDataType;+ DataTypeComponent dtc = composite.getComponent(index);Address componentAddr = address.add(dtc.getOffset());return new DataComponent(codeMgr, componentCache, componentAddr,addressMap.getKey(componentAddr, false), this, dtc);-}if (baseDataType instanceof DynamicDataType) {DynamicDataType ddt = (DynamicDataType) baseDataType;