Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-0: Guard the buffer truncation with Reason.EXECUTE_DECODE

Dandeaa24a496b6
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/exec/BytesPcodeExecutorStateSpace.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/exec/BytesPcodeExecutorStateSpace.java
index 757de237a5..7bb578de05 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/exec/BytesPcodeExecutorStateSpace.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/exec/BytesPcodeExecutorStateSpace.java
@@ -185,12 +185,18 @@ public class BytesPcodeExecutorStateSpace<B> {
}
}
- Iterator<ULongSpan> it =
- uninitialized.complement(ULongSpan.extent(offset, size)).iterator();
- if (it.hasNext()) {
- ULongSpan init = it.next();
- if (init.min().longValue() == offset) {
- return readBytes(offset, (int) init.length(), reason);
+ /**
+ * The decoder will buffer ahead, so give it as much as we can, but no more than is actually
+ * initialized. If it's a (non-decode) read, give it everything, but invoke the warning.
+ */
+ if (reason == Reason.EXECUTE_DECODE) {
+ Iterator<ULongSpan> it =
+ uninitialized.complement(ULongSpan.extent(offset, size)).iterator();
+ if (it.hasNext()) {
+ ULongSpan init = it.next();
+ if (init.min().longValue() == offset) {
+ return readBytes(offset, (int) init.length(), reason);
+ }
}
}