Added bounds check to copyRange.

This commit is contained in:
Ioannis Tsakpinis 2011-07-12 20:40:05 +00:00
parent a75b1dde68
commit 5158d53dec
2 changed files with 16 additions and 1 deletions

View File

@ -106,6 +106,11 @@ public class MappedHelper {
}
public static void copy(MappedObject src, MappedObject dst, int bytes) {
if ( MappedObject.CHECKS ) {
src.checkRange(bytes);
dst.checkRange(bytes);
}
MappedObjectUnsafe.INSTANCE.copyMemory(src.viewAddress, dst.viewAddress, bytes);
}

View File

@ -33,6 +33,7 @@ package org.lwjgl.util.mapped;
import org.lwjgl.LWJGLUtil;
import java.nio.BufferOverflowException;
import java.nio.ByteBuffer;
/**
@ -97,10 +98,19 @@ public class MappedObject {
}
final void checkAddress(final long address) {
if ( preventGC.capacity() < (address - MappedObjectUnsafe.getBufferBaseAddress(preventGC) + stride) )
final long base = MappedObjectUnsafe.getBufferBaseAddress(preventGC);
if ( address < base || preventGC.capacity() < (address - base + stride) )
throw new IndexOutOfBoundsException();
}
final void checkRange(final int bytes) {
if ( bytes < 0 )
throw new IllegalArgumentException();
if ( preventGC.capacity() < (viewAddress - MappedObjectUnsafe.getBufferBaseAddress(preventGC) + bytes) )
throw new BufferOverflowException();
}
/**
* Creates a MappedObject instance, mapping the memory region of the specified direct ByteBuffer.
* <p/>