{"record":{"id":"c20ef5fda8cc5762","repo":"NationalSecurityAgency/ghidra","slug":"could-unit-would-extend-beyond-address-space","errorCode":null,"errorMessage":"Could unit would extend beyond address space","messagePattern":"Could unit would extend beyond address space","errorType":"exception","errorClass":"CodeUnitInsertionException","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/listing/DBTraceDefinedDataView.java","lineNumber":169,"sourceCode":"\t\t\t// TODO: Explicitly remove undefined from cache, or let weak refs take care of it?\n\n\t\t\tcacheForContaining.notifyNewEntry(tasr.getLifespan(), createdRange, created);\n\t\t\tcacheForSequence.notifyNewEntry(tasr.getLifespan(), createdRange, created);\n\t\t\tspace.undefinedData.invalidateCache();\n\n\t\t\tif (dataType instanceof Composite || dataType instanceof Array ||\n\t\t\t\tdataType instanceof Dynamic) {\n\t\t\t\t// TODO: Track composites?\n\t\t\t\tspace.trace.setChanged(new TraceChangeRecord<>(TraceEvents.COMPOSITE_DATA_ADDED,\n\t\t\t\t\tspace.space, tasr, created));\n\t\t\t}\n\n\t\t\tspace.trace.setChanged(\n\t\t\t\tnew TraceChangeRecord<>(TraceEvents.CODE_ADDED, space.space, tasr, created));\n\t\t\treturn created;\n\t\t}\n\t\tcatch (AddressOverflowException e) {\n\t\t\tthrow new CodeUnitInsertionException(\"Could unit would extend beyond address space\");\n\t\t}\n\t}\n\n}\n","sourceCodeStart":151,"sourceCodeEnd":174,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/listing/DBTraceDefinedDataView.java#L151-L174","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nview.create(lifespan, nearMaxAddress, platform, largeStructType); // overflows\n\n// after — check remaining space\nlong remaining = addressSpace.getMaxAddress().subtract(address);\nif (remaining >= dataType.getLength() - 1) {\n    view.create(lifespan, address, platform, dataType);\n} else {\n    // pick a different address or smaller type\n}","handlingStrategy":"validation","validationCode":"// Verify address space capacity before creating\nint length = dataType.getLength();\nAddress maxAddr = address.getAddressSpace().getMaxAddress();\nif (maxAddr.subtract(address) < length - 1) {\n    // Not enough room — choose a different address or smaller type\n    throw new IllegalArgumentException(\n        \"Data type would overflow address space at \" + address);\n}\nview.create(lifespan, address, platform, dataType, length);","typeGuard":null,"tryCatchPattern":"try {\n    view.create(lifespan, address, platform, dataType, length);\n} catch (CodeUnitInsertionException e) {\n    if (e.getMessage().contains(\"beyond address space\")) {\n        // Use a smaller type or move the address earlier\n        view.create(lifespan, earlierAddress, platform, dataType, length);\n    } else {\n        throw e;\n    }\n}","preventionTips":["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."],"tags":["address-overflow","create","address-space","trace-modeling"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}