3
0
mirror of https://github.com/Qortal/AT.git synced 2025-01-30 10:52:14 +00:00

Fix off-by-one error with data address bounds & unit test to cover

This commit is contained in:
catbref 2020-06-09 10:57:39 +01:00
parent 3c17db0c46
commit 09d2b5be1f
2 changed files with 15 additions and 1 deletions

View File

@ -71,7 +71,7 @@ interface Utils {
try { try {
final int address = codeByteBuffer.getInt() * MachineState.VALUE_SIZE; final int address = codeByteBuffer.getInt() * MachineState.VALUE_SIZE;
if (address < 0 || address + MachineState.VALUE_SIZE >= dataByteBuffer.limit()) if (address < 0 || address + MachineState.VALUE_SIZE > dataByteBuffer.limit())
throw new InvalidAddressException("Data address out of bounds"); throw new InvalidAddressException("Data address out of bounds");
return address; return address;

View File

@ -68,4 +68,18 @@ public class MiscTests extends ExecutableTest {
assertEquals((Long) (minActivationAmount - 1L), state.getFrozenBalance()); assertEquals((Long) (minActivationAmount - 1L), state.getFrozenBalance());
} }
@Test
public void testDataAddressBounds() throws ExecutionException {
// Last possible valid address in data segment
int lastDataAddress = (dataByteBuffer.limit() / MachineState.VALUE_SIZE) - 1;
codeByteBuffer.put(OpCode.SET_VAL.value).putInt(lastDataAddress).putLong(8888L);
codeByteBuffer.put(OpCode.FIN_IMD.value);
execute(true);
assertTrue(state.isFinished());
assertFalse(state.hadFatalError());
}
} }