NationalSecurityAgency/ghidra · error · MemoryAccessException
Could not read enough bytes
Error message
Could not read enough bytes
What it means
getBytesInFull allocates a buffer of len and calls getBytes(buf, address); if fewer than len bytes were read it throws MemoryAccessException("Could not read enough bytes"). The mapped memory could not satisfy the full requested length, typically because the read crosses the end of a mapped host region or runs into unmapped host backing.
Source
Thrown at Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/guest/DBTraceGuestPlatformMappedMemory.java:380
buffer.position(buffer.position() + lenToRead);
continue;
}
int savedLimit = buffer.limit();
try {
buffer.limit(buffer.position() + lenToRead);
hostSpace.getViewBytes(snap, hostCur, buffer);
}
finally {
buffer.limit(savedLimit);
}
}
return buffer.position() - startPos;
}
protected ByteBuffer getBytesInFull(Address address, int len) throws MemoryAccessException {
ByteBuffer buf = ByteBuffer.allocate(len);
if (getBytes(buf, address) != len) {
throw new MemoryAccessException("Could not read enough bytes");
}
if (!isBigEndian()) {
buf.order(ByteOrder.LITTLE_ENDIAN);
}
return buf;
}
@Override
public byte getByte(Address addr) throws MemoryAccessException {
byte[] val = new byte[1];
if (getBytes(addr, val) < 1) {
throw new MemoryAccessException("Guest address " + addr.toString() +
" is not mapped, or the mapped address does not exist in host memory");
}
return val[0];
}
@OverrideView on GitHub (pinned to d5f144c24d)
Solutions
- Reduce the requested length or read byte-wise across the boundary.
- Ensure the full host range backing the guest address is populated for the snapshot before reading.
- Catch MemoryAccessException and degrade to a partial read.
Example fix
// before
ByteBuffer buf = mem.getBytesInFull(addr, 8);
// after
ByteBuffer buf = ByteBuffer.allocate(8);
int got = mem.getBytes(buf, addr);
if (got != 8) { /* handle partial read */ } Defensive patterns
Strategy: try-catch
Validate before calling
ByteBuffer buf = ByteBuffer.allocate(len);
int got = mem.getBytes(buf, address);
if (got < len) { /* shorten read or ensure full host backing */ } Try / catch
try { ByteBuffer buf = mem.getBytesInFull(addr, len); }
catch (MemoryAccessException e) { /* partial/short read: handle gracefully */ } Prevention
- Read byte-wise when crossing mapping boundaries.
- Populate the full host backing range for the snapshot before multi-byte reads.
- Treat short reads as expected near range edges, not as fatal.
When it happens
Trigger: Reading a multi-byte value (int/long) that straddles the boundary of a mapped host region; reading past a partial mapping; getBytes returning short due to unmapped host snapshot.
Common situations: Emulation dereferencing guest memory near range edges; reading values that cross mapping boundaries; snapshot where part of the host range has no written bytes.
Related errors
- Guest address ${addr} is not mapped, or the mapped address d
- Space does not exist
- %s: %s
- Failed to read memory
- TODO: Unoptimized byte diff
AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14).
Data as JSON: /api/errors/6ccb03450d568a02.
Report an issue: GitHub.