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

  1. Choose a start address and length whose sum (start + length - 1) does not exceed the address space max.
  2. Validate before applying: address.addNoWrap(length - 1) in a try/catch and surface a user-friendly message.
  3. 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

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


AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14). Data as JSON: /api/errors/2f4bcf6d6dc17311. Report an issue: GitHub.