NationalSecurityAgency/ghidra · error · CodeUnitInsertionException
Could unit would extend beyond address space
Error message
Could unit would extend beyond address space
What it means
Thrown by DBTraceDefinedDataView.create() when address.addNoWrap(length - 1) throws AddressOverflowException — the computed end address (start + length - 1) exceeds the maximum address of the address space. This is caught and wrapped as a CodeUnitInsertionException so callers see a uniform exception type. The data unit would extend past the end of the addressable range, which is impossible.
Source
Thrown at Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/listing/DBTraceDefinedDataView.java:169
// TODO: Explicitly remove undefined from cache, or let weak refs take care of it?
cacheForContaining.notifyNewEntry(tasr.getLifespan(), createdRange, created);
cacheForSequence.notifyNewEntry(tasr.getLifespan(), createdRange, created);
space.undefinedData.invalidateCache();
if (dataType instanceof Composite || dataType instanceof Array ||
dataType instanceof Dynamic) {
// TODO: Track composites?
space.trace.setChanged(new TraceChangeRecord<>(TraceEvents.COMPOSITE_DATA_ADDED,
space.space, tasr, created));
}
space.trace.setChanged(
new TraceChangeRecord<>(TraceEvents.CODE_ADDED, space.space, tasr, created));
return created;
}
catch (AddressOverflowException e) {
throw new CodeUnitInsertionException("Could unit would extend beyond address space");
}
}
}
View on GitHub (pinned to d5f144c24d)
Solutions
- Choose a start address that has enough room for the full data type length.
- Use a smaller data type that fits in the remaining address space.
- Validate: addressSpace.getMaxAddress().subtract(address) >= length - 1 before creating.
Example fix
// before
view.create(lifespan, nearMaxAddress, platform, largeStructType); // overflows
// after — check remaining space
long remaining = addressSpace.getMaxAddress().subtract(address);
if (remaining >= dataType.getLength() - 1) {
view.create(lifespan, address, platform, dataType);
} else {
// pick a different address or smaller type
} Defensive patterns
Strategy: validation
Validate before calling
// Verify address space capacity before creating
int length = dataType.getLength();
Address maxAddr = address.getAddressSpace().getMaxAddress();
if (maxAddr.subtract(address) < length - 1) {
// Not enough room — choose a different address or smaller type
throw new IllegalArgumentException(
"Data type would overflow address space at " + address);
}
view.create(lifespan, address, platform, dataType, length); Try / catch
try {
view.create(lifespan, address, platform, dataType, length);
} catch (CodeUnitInsertionException e) {
if (e.getMessage().contains("beyond address space")) {
// Use a smaller type or move the address earlier
view.create(lifespan, earlierAddress, platform, dataType, length);
} else {
throw e;
}
} Prevention
- Check remaining address space: maxAddress.subtract(address) >= length - 1 before creating.
- Avoid placing large struct/array types near the top of small address spaces.
- Validate address + length against the address space boundary in bulk annotation scripts.
When it happens
Trigger: Calling create() with a data type whose length, when added to the start address, overflows the address space boundary. E.g., placing a 4-byte integer at the last 2 bytes of a 32-bit address space (0xFFFFFFFE).
Common situations: Creating data types near the top of a small address space; using a length larger than the remaining space at the address; misconfigured address space size; large struct/array types placed too close to the space boundary.
Related errors
- Register {register} does not map to space {space}'s physical
- Memory-mapped register {register} does not map to space {spa
- Platform is not part of this trace
- Code units cannot overlap
- Failed to resolve data type
AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14).
Data as JSON: /api/errors/c20ef5fda8cc5762.
Report an issue: GitHub.