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 DefaultWatchRow.setRawValueBytes when the supplied byte array is longer than the watch's fixed value buffer. Mirrors the variable-viewer length check: writes must fit within the watch's declared length.
Source
Thrown at Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/watch/DefaultWatchRow.java:467
final BigInteger val;
if (intString.startsWith("0x")) {
val = new BigInteger(intString.substring(2), 16);
}
else {
val = new BigInteger(intString, 10);
}
setRawValueBytes(
Utils.bigIntegerToBytes(val, value.length, provider.language.isBigEndian()));
}
public void setRawValueBytes(byte[] bytes) {
synchronized (lock) {
if (address == null) {
throw new IllegalStateException(
"Cannot write to watch variable without an address");
}
if (bytes.length > value.length) {
throw new IllegalArgumentException("Byte arrays cannot exceed length of variable");
}
if (bytes.length < value.length) {
byte[] fillOld = Arrays.copyOf(value, value.length);
System.arraycopy(bytes, 0, fillOld, 0, bytes.length);
bytes = fillOld;
}
DebuggerControlService controlService = provider.controlService;
if (controlService == null) {
throw new AssertionError("No control service");
}
StateEditor editor = controlService.createStateEditor(provider.current);
editor.setVariable(address, bytes).exceptionally(ex -> {
Msg.showError(this, null, "Write Failed",
"Could not modify watch value (on target)", ex);
return null;
});
}
}View on GitHub (pinned to d5f144c24d)
Solutions
- Trim the byte array to value.length before writing.
- Recreate the watch with the correct (wider) length/type if more bytes are needed.
- Validate byte length against getValueLength() in the UI.
- Use Utils.bigIntegerToBytes(val, value.length, bigEndian) which sizes to the variable.
Example fix
// before
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 <= row.getValueLength();
Type guard
static boolean fitsWatch(byte[] bytes, int valueLen) {
return bytes.length <= valueLen;
} Try / catch
try {
row.setRawValueBytes(bytes);
} catch (IllegalArgumentException e) {
bytes = Arrays.copyOf(bytes, row.getValueLength());
} Prevention
- Size bytes to getValueLength() before writing.
- Use bigIntegerToBytes with the watch length.
When it happens
Trigger: Calling setRawValueBytes(bytes) where bytes.length > value.length inside the synchronized write block.
Common situations: Pasting a hex/byte literal wider than the watch's register/variable size; converting a larger integer into a narrow watch; type-length mismatch between the watch and supplied bytes.
Related errors
- Byte arrays cannot exceed length of variable
- Byte array values must be hex enclosed in {}
- Invalid number of elements specified: {}
- pos cannot be less than zero
- %s: unknown demangling style `%s'
AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14).
Data as JSON: /api/errors/478f401da139b9b8.
Report an issue: GitHub.