NationalSecurityAgency/ghidra · error · CodeUnitInsertionException

Zero-length data not allowed {origType.getName}

Error message

Zero-length data not allowed {origType.getName}

What it means

Thrown by DBTraceDefinedDataView.create() when the resolved data length is exactly 0. A zero-length data unit has no address range and is semantically meaningless, so the model rejects it. This can happen when a data type's getLength() returns 0, or when a Dynamic type's getLength(buffer, length) computes 0 (e.g., an empty structure or a string type that finds an immediate terminator).

Source

Thrown at Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/listing/DBTraceDefinedDataView.java:128

				length = dataType.getLength();
			}
			else if (dataType instanceof Dynamic) {
				// TODO: Should I consider no observations to be "uninitialized"?
				// If so, dynamic types cannot be applied here
				Dynamic dyn = (Dynamic) dataType;
				MemBuffer buffer = memSpace.getBufferAt(startSnap, address);
				length = dyn.getLength(buffer, length);
			}
			else {
				length = dataType.getLength();
			}

			if (length < 0) {
				throw new CodeUnitInsertionException(
					"Failed to resolve data length for " + origType.getName());
			}
			if (length == 0) {
				throw new CodeUnitInsertionException(
					"Zero-length data not allowed " + origType.getName());
			}

			Address endAddress = address.addNoWrap(length - 1);
			AddressRangeImpl createdRange = new AddressRangeImpl(address, endAddress);

			// Truncate, then check that against existing code units.
			long endSnap = computeTruncatedMax(lifespan, null, createdRange);
			TraceAddressSnapRange tasr =
				new ImmutableTraceAddressSnapRange(createdRange, Lifespan.span(startSnap, endSnap));
			if (!space.undefinedData.coversRange(tasr)) {
				// TODO: Figure out the conflicting unit?
				throw new CodeUnitInsertionException("Code units cannot overlap");
			}

			if (dataType == DataType.DEFAULT) {
				return space.undefinedData.getAt(startSnap, address);
			}

View on GitHub (pinned to d5f144c24d)

Solutions

  1. Ensure the data type and memory produce a non-zero length — check dataType.getLength() or the Dynamic result before creating.
  2. Use a minimum-length data type (e.g., ByteDataType for a single byte) instead.
  3. If applying a string type, ensure there is at least one non-terminator byte at the address.
  4. Validate: if computed length == 0, skip the create call or log a warning.

Example fix

// before
view.create(lifespan, address, platform, TerminatedStringDataType.dataType);
// address has only \x00 — length resolves to 0

// after — ensure meaningful bytes, or use a different type
if (memSpace.getByte(snap, address) != 0) {
    view.create(lifespan, address, platform, TerminatedStringDataType.dataType);
} else {
    view.create(lifespan, address, platform, ByteDataType.dataType);
}
Defensive patterns

Strategy: validation

Validate before calling

// Compute and check length before creating
int expectedLength = (dataType instanceof Dynamic dyn)
    ? dyn.getLength(memSpace.getBufferAt(startSnap, address), dataType.getLength())
    : dataType.getLength();
if (expectedLength == 0) {
    // Zero-length not allowed — use a minimum-size type or skip
    return;
}
view.create(lifespan, address, platform, dataType, expectedLength);

Try / catch

try {
    view.create(lifespan, address, platform, dataType, length);
} catch (CodeUnitInsertionException e) {
    if (e.getMessage().startsWith("Zero-length data not allowed")) {
        // Use a minimal fixed type instead
        view.create(lifespan, address, platform, ByteDataType.dataType, 1);
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: Calling create() where the final computed length == 0. This occurs with empty composites, Dynamic types that resolve to zero bytes (e.g., TerminatedStringDataType over a single null byte), or when origLength is explicitly passed as 0 for a fixed type.

Common situations: Applying a string type to an address that contains only a null terminator; empty struct definitions; explicitly passing 0 as length; Dynamic type whose computed length collapses to zero on specific byte patterns.

Related errors


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