NationalSecurityAgency/ghidra · error · CodeUnitInsertionException
Failed to resolve data length for {origType.getName}
Error message
Failed to resolve data length for {origType.getName} What it means
Thrown by DBTraceDefinedDataView.create() when the resolved data length is negative (< 0), meaning the data type could not determine a valid byte length from the available information. For fixed types this means getLength() returned -1; for Dynamic types, dyn.getLength(buffer, length) returned -1. A data unit requires a known positive length to define its address range, so a negative length prevents unit creation.
Source
Thrown at Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/listing/DBTraceDefinedDataView.java:124
dataType = dataType.clone(dtm);
if (isFunctionDefinition(dataType)) {
dataType = new PointerDataType(dataType, dtm);
length = dataType.getLength();
}
else if (dataType instanceof Dynamic) {
// TODO: Should I consider no observations to be "uninitialized"?
// If so, dynamic types cannot be applied here
Dynamic dyn = (Dynamic) dataType;
MemBuffer buffer = memSpace.getBufferAt(startSnap, address);
length = dyn.getLength(buffer, length);
}
else {
length = dataType.getLength();
}
if (length < 0) {
throw new CodeUnitInsertionException(
"Failed to resolve data length for " + origType.getName());
}
if (length == 0) {
throw new CodeUnitInsertionException(
"Zero-length data not allowed " + origType.getName());
}
Address endAddress = address.addNoWrap(length - 1);
AddressRangeImpl createdRange = new AddressRangeImpl(address, endAddress);
// Truncate, then check that against existing code units.
long endSnap = computeTruncatedMax(lifespan, null, createdRange);
TraceAddressSnapRange tasr =
new ImmutableTraceAddressSnapRange(createdRange, Lifespan.span(startSnap, endSnap));
if (!space.undefinedData.coversRange(tasr)) {
// TODO: Figure out the conflicting unit?
throw new CodeUnitInsertionException("Code units cannot overlap");
}View on GitHub (pinned to d5f144c24d)
Solutions
- Provide an explicit positive origLength when the type is variable: use the create(lifespan, address, platform, dataType, length) overload with a concrete length.
- Ensure memory bytes are written so Dynamic types can compute length: trace.getMemoryManager().putBytes().
- Use a fixed-size DataType that has a known getLength().
Example fix
// before — variable-length type with no resolvable length view.create(lifespan, address, platform, dynamicType); // length < 0 // after — pass explicit length or ensure bytes are present view.create(lifespan, address, platform, dynamicType, 16); // explicit length // OR write the expected bytes first: trace.getMemoryManager().putBytes(snap, address, dataWithTerminator);
Defensive patterns
Strategy: validation
Validate before calling
// Compute expected length before creating
int expectedLength;
if (dataType instanceof Dynamic dyn) {
MemBuffer buffer = memSpace.getBufferAt(startSnap, address);
expectedLength = dyn.getLength(buffer, dataType.getLength());
} else {
expectedLength = dataType.getLength();
}
if (expectedLength < 0) {
// Provide explicit length using the overloaded create method
view.create(lifespan, address, platform, dataType, explicitLength);
return;
}
view.create(lifespan, address, platform, dataType); Try / catch
try {
view.create(lifespan, address, platform, dataType, length);
} catch (CodeUnitInsertionException e) {
if (e.getMessage().startsWith("Failed to resolve data length")) {
// Length unresolvable — pass explicit length or use a fixed type
view.create(lifespan, address, platform, ByteDataType.dataType, 1);
} else {
throw e;
}
} Prevention
- Always pass an explicit length via the 5-argument create() overload for variable-length types.
- Write memory bytes before applying Dynamic data types so length can be computed.
- Check dataType.getLength() before creating — if -1, use the explicit-length overload.
When it happens
Trigger: Calling create() with a DataType whose getLength() returns -1 (unsized/variable type) and is not Dynamic (or is Dynamic but getLength returned -1). For Dynamic types, this happens when dyn.getLength(buffer, length) cannot compute a size from the memory buffer — e.g., insufficient or non-matching bytes.
Common situations: Applying a variable-length data type at uninitialized memory; Dynamic type (e.g., a string type) that cannot determine its length because the terminator or size field is absent; using a data type from a different architecture that expects different byte patterns.
Related errors
- Failed to resolve data type
- Zero-length data not allowed {origType.getName}
- Data table is corrupt. Missing datatype: {dataTypeID}
- Data table is corrupt. Data unit and its datatype disagree o
- Platform is not part of this trace
AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14).
Data as JSON: /api/errors/1c8f69f0585a107f.
Report an issue: GitHub.