{"record":{"id":"2f4bcf6d6dc17311","repo":"NationalSecurityAgency/ghidra","slug":"can-t-create-structure-because-length-exceeds-addr","errorCode":null,"errorMessage":"Can't create structure because length exceeds address space","messagePattern":"Can't create structure because length exceeds address space","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/Base/src/main/java/ghidra/app/cmd/data/CreateStructureCmd.java","lineNumber":96,"sourceCode":"\t\tif (structure == null) {\n\t\t\tstructure = StructureFactory.createStructureDataType(program, address,\n\t\t\t\tstructureDataLength, getStructureName(), true);\n\t\t}\n\n\t\treturn structure;\n\t}\n\n\t@Override\n\tDataType initializeStructureData(Program program, Structure localStructure) {\n\n\t\tListing listing = program.getListing();\n\n\t\tAddress endAddress;\n\t\ttry {\n\t\t\tendAddress = getStructureAddress().addNoWrap(structureDataLength - 1);\n\t\t}\n\t\tcatch (AddressOverflowException e1) {\n\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\"Can't create structure because length exceeds address space\" +\n\t\t\t\t\tstructureDataLength);\n\t\t}\n\t\tReferenceManager refMgr = program.getReferenceManager();\n\t\tList<Reference> refs = findExistingRefs(refMgr, program.getAddressFactory(),\n\t\t\tgetStructureAddress(), endAddress);\n\t\tlisting.clearCodeUnits(getStructureAddress(), endAddress, false);\n\n\t\tData data = null;\n\t\ttry {\n\t\t\tlisting.createData(getStructureAddress(), localStructure, localStructure.getLength());\n\t\t\trefMgr.removeAllReferencesFrom(getStructureAddress(), endAddress);\n\t\t\taddRefs(program, refMgr, refs);\n\t\t\tdata = listing.getDataAt(getStructureAddress());\n\t\t}\n\t\tcatch (CodeUnitInsertionException e) {\n\t\t\tthrow new IllegalArgumentException(e.getMessage());\n\t\t}","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/Base/src/main/java/ghidra/app/cmd/data/CreateStructureCmd.java#L78-L114","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nnew CreateStructureCmd(addr, length).applyTo(program);\n// addr near max -> addNoWrap throws -> IllegalArgumentException\n\n// after\ntry {\n    addr.addNoWrap(length - 1);\n} catch (AddressOverflowException e) {\n    throw new IllegalArgumentException(\n        \"Structure of length \" + length + \" at \" + addr + \" exceeds address space\");\n}\nnew CreateStructureCmd(addr, length).applyTo(program);","handlingStrategy":"validation","validationCode":"try {\n    getStructureAddress().addNoWrap(structureDataLength - 1);\n} catch (AddressOverflowException e) {\n    // do not invoke CreateStructureCmd with this start+length\n}","typeGuard":"boolean fitsInAddressSpace(Address start, int length) {\n    try {\n        start.addNoWrap(length - 1);\n        return true;\n    } catch (AddressOverflowException e) {\n        return false;\n    }\n}","tryCatchPattern":"try {\n    cmd.applyTo(program);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Can't create structure because length exceeds\")) {\n        // reduce length or move start address earlier\n    } else throw e;\n}","preventionTips":["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."],"tags":["structure","address","command","overflow"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}