NationalSecurityAgency/ghidra · error · IllegalArgumentException
Byte arrays cannot exceed length of variable
Error message
Byte arrays cannot exceed length of variable
What it means
Thrown by AbstractDebuggerVariableViewerVarValue.setRawValueBytes when the supplied byte array is longer than the variable's own value buffer. The variable has a fixed length; the caller must truncate or pad to fit, never exceed.
Source
Thrown at Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/variable/AbstractDebuggerVariableViewerVarValue.java:121
new ByteMemBufferImpl(address, value, language.isBigEndian()), NO_SETTINGS,
value.length);
setRawValueBytes(encoded);
}
catch (final DataTypeEncodeException e) {
Msg.error(this, e.getMessage());
}
}
abstract DataType getDataType();
abstract void setDataType(DataType dataType);
private void setRawValueBytes(byte[] bytes) {
if (address == null) {
throw new IllegalStateException("Cannot write to variable without an address");
}
if (bytes.length > value.length) {
throw new IllegalArgumentException("Byte arrays cannot exceed length of variable");
}
if (bytes.length < value.length) {
final byte[] fillOld = Arrays.copyOf(value, value.length);
System.arraycopy(bytes, 0, fillOld, 0, bytes.length);
bytes = fillOld;
}
final DebuggerControlService controlService = provider.controlService;
if (controlService == null) {
throw new AssertionError("No control service");
}
final DebuggerControlService.StateEditor editor =
controlService.createStateEditor(provider.currentCoordinates);
editor.setVariable(address, bytes).exceptionally(ex -> {
Msg.showError(this, null, "Write Failed", "Could not modify value (on target)", ex);
return null;
});
}View on GitHub (pinned to d5f144c24d)
Solutions
- Truncate or resize the byte array to the variable's length (value.length) before calling setRawValueBytes.
- Validate input length against the variable's DataType length in the UI before submission.
- Change the variable's declared type to a wider one if more bytes are genuinely required.
- Use NumericUtilities to convert a number to a fixed-width byte array of the correct length.
Example fix
// before
byte[] bytes = ...; // possibly too long
setRawValueBytes(bytes); // throws if bytes.length > value.length
// after
if (bytes.length > value.length) {
bytes = Arrays.copyOf(bytes, value.length);
}
setRawValueBytes(bytes); Defensive patterns
Strategy: validation
Validate before calling
boolean ok = bytes.length <= value.length;
Type guard
static boolean fitsVariable(byte[] bytes, byte[] value) {
return bytes.length <= value.length;
} Try / catch
try {
varValue.setRawValueBytes(bytes);
} catch (IllegalArgumentException e) {
bytes = Arrays.copyOf(bytes, value.length);
} Prevention
- Always size byte arrays to the variable's DataType length.
- Use fixed-width converters (Utils.bigIntegerToBytes).
When it happens
Trigger: Calling setRawValueBytes(bytes) where bytes.length > value.length (value is the variable's fixed-size backing buffer derived from its DataType length).
Common situations: Paste of a hex string that decodes to more bytes than the variable's type; programming error converting a wider integer into a narrower variable; mismatch between the declared variable size and the bytes supplied by the UI.
Related errors
- Byte arrays cannot exceed length of variable
- Byte array values must be hex enclosed in {}
- data and mask must have same capacity
- Length must match the register
- Space must be a memory, register, or NO_ADDRESS space
AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14).
Data as JSON: /api/errors/123640f38584c624.
Report an issue: GitHub.