NationalSecurityAgency/ghidra · error · IllegalArgumentException
Can't create structure because length exceeds address space
Error message
Can't create structure because length exceeds address space
What it means
Thrown by CreateStructureCmd.initializeStructureData when computing the structure's end address via getStructureAddress().addNoWrap(structureDataLength - 1) overflows the address space. addNoWrap throws AddressOverflowException, which the command rethrows as IllegalArgumentException. It means the structure would extend past the maximum address of the address space.
Source
Thrown at Ghidra/Features/Base/src/main/java/ghidra/app/cmd/data/CreateStructureCmd.java:96
if (structure == null) {
structure = StructureFactory.createStructureDataType(program, address,
structureDataLength, getStructureName(), true);
}
return structure;
}
@Override
DataType initializeStructureData(Program program, Structure localStructure) {
Listing listing = program.getListing();
Address endAddress;
try {
endAddress = getStructureAddress().addNoWrap(structureDataLength - 1);
}
catch (AddressOverflowException e1) {
throw new IllegalArgumentException(
"Can't create structure because length exceeds address space" +
structureDataLength);
}
ReferenceManager refMgr = program.getReferenceManager();
List<Reference> refs = findExistingRefs(refMgr, program.getAddressFactory(),
getStructureAddress(), endAddress);
listing.clearCodeUnits(getStructureAddress(), endAddress, false);
Data data = null;
try {
listing.createData(getStructureAddress(), localStructure, localStructure.getLength());
refMgr.removeAllReferencesFrom(getStructureAddress(), endAddress);
addRefs(program, refMgr, refs);
data = listing.getDataAt(getStructureAddress());
}
catch (CodeUnitInsertionException e) {
throw new IllegalArgumentException(e.getMessage());
}View on GitHub (pinned to d5f144c24d)
Solutions
- Choose a start address and length whose sum (start + length - 1) does not exceed the address space max.
- Validate before applying: address.addNoWrap(length - 1) in a try/catch and surface a user-friendly message.
- Reduce the structure length or move the start address earlier.
Example fix
// before
new CreateStructureCmd(addr, length).applyTo(program);
// addr near max -> addNoWrap throws -> IllegalArgumentException
// after
try {
addr.addNoWrap(length - 1);
} catch (AddressOverflowException e) {
throw new IllegalArgumentException(
"Structure of length " + length + " at " + addr + " exceeds address space");
}
new CreateStructureCmd(addr, length).applyTo(program); Defensive patterns
Strategy: validation
Validate before calling
try {
getStructureAddress().addNoWrap(structureDataLength - 1);
} catch (AddressOverflowException e) {
// do not invoke CreateStructureCmd with this start+length
} Type guard
boolean fitsInAddressSpace(Address start, int length) {
try {
start.addNoWrap(length - 1);
return true;
} catch (AddressOverflowException e) {
return false;
}
} Try / catch
try {
cmd.applyTo(program);
} catch (IllegalArgumentException e) {
if (e.getMessage().startsWith("Can't create structure because length exceeds")) {
// reduce length or move start address earlier
} else throw e;
} Prevention
- Validate start + length - 1 with addNoWrap before creating the command.
- Avoid creating structures at the very end of a memory block or address space.
- Sanity-check large lengths before applying.
When it happens
Trigger: Constructing/applyTo-ing a CreateStructureCmd with a start address near the top of the address space and a length that would exceed the max address. E.g. start at 0xFFFFFFF0 in a 32-bit space with length 32.
Common situations: Creating a structure at the very end of a memory block or near the address-space boundary. Accidentally passing an extremely large length. Operating on a small overlay or register space.
Related errors
- Data not in a structure
- Cannot write to watch variable without an address
- Address does not belong to a memory in the trace
- Bad address format: {}
- Address requires a trace for context
AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14).
Data as JSON: /api/errors/2f4bcf6d6dc17311.
Report an issue: GitHub.