Ghidra is a software reverse engineering (SRE) framework
GP-2011: Fix AddressOutOfBounds issue in mapper
Dancd40985bccd2
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/modules/DebuggerStaticMappingServicePlugin.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/modules/DebuggerStaticMappingServicePlugin.javaindex c3c66b0388..585ba142c4 100644--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/modules/DebuggerStaticMappingServicePlugin.java+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/modules/DebuggerStaticMappingServicePlugin.java@@ -95,13 +95,12 @@ public class DebuggerStaticMappingServicePlugin extends Plugin}public Address addOrMax(Address start, long length) {- try {- return start.addNoWrap(length);- }- catch (AddressOverflowException e) {- Msg.warn(this, "Mapping entry cause overflow in static address space");+ Address result = start.addWrapSpace(length);+ if (result.compareTo(start) < 0) {+ Msg.warn(this, "Mapping entry caused overflow in static address space");return start.getAddressSpace().getMaxAddress();}+ return result;}public boolean programOpened(Program opened) {@@ -176,7 +175,7 @@ public class DebuggerStaticMappingServicePlugin extends Pluginprotected Address mapTraceAddressToProgram(Address address) {assert isInTraceRange(address, null);long offset = address.subtract(mapping.getMinTraceAddress());- return staticRange.getMinAddress().add(offset);+ return staticRange.getMinAddress().addWrapSpace(offset);}public ProgramLocation mapTraceAddressToProgramLocation(Address address) {@@ -197,7 +196,7 @@ public class DebuggerStaticMappingServicePlugin extends Pluginprotected Address mapProgramAddressToTrace(Address address) {assert isInProgramRange(address);long offset = address.subtract(staticRange.getMinAddress());- return mapping.getMinTraceAddress().add(offset);+ return mapping.getMinTraceAddress().addWrapSpace(offset);}protected TraceLocation mapProgramAddressToTraceLocation(Address address) {diff --git a/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/service/modules/DebuggerStaticMappingServiceTest.java b/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/service/modules/DebuggerStaticMappingServiceTest.javaindex 7b2d1a4049..ab0f71a982 100644--- a/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/service/modules/DebuggerStaticMappingServiceTest.java+++ b/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/service/modules/DebuggerStaticMappingServiceTest.java@@ -611,4 +611,27 @@ public class DebuggerStaticMappingServiceTest extends AbstractGhidraHeadedDebuggDebuggerStaticMappingProposals.groupRegionsByLikelyModule(mm.getAllRegions());assertEquals(Set.of(Set.of(echoText, echoData), Set.of(libText, libData)), actual);}++ protected void assertMapsTwoWay(long stOff, long dynOff) {+ TraceLocation dynLoc =+ new DefaultTraceLocation(tb.trace, null, Range.atLeast(0L), tb.addr(dynOff));+ ProgramLocation stLoc = new ProgramLocation(program, stSpace.getAddress(stOff));+ assertEquals(stLoc, mappingService.getOpenMappedLocation(dynLoc));+ assertEquals(dynLoc, mappingService.getOpenMappedLocation(tb.trace, stLoc, 0));+ }++ @Test+ public void testMapFullSpace() throws Exception {+ try (UndoableTransaction tid = tb.startTransaction()) {+ TraceLocation traceLoc =+ new DefaultTraceLocation(tb.trace, null, Range.atLeast(0L), tb.addr(0));+ ProgramLocation progLoc = new ProgramLocation(program, stSpace.getAddress(0));+ // NB. 0 indicates 1 << 64+ mappingService.addMapping(traceLoc, progLoc, 0, true);+ }+ waitForPass(() -> assertMapsTwoWay(0L, 0L));+ assertMapsTwoWay(-1L, -1L);+ assertMapsTwoWay(Long.MAX_VALUE, Long.MAX_VALUE);+ assertMapsTwoWay(Long.MIN_VALUE, Long.MIN_VALUE);+ }}