Added bounds check to copyRange.
This commit is contained in:
parent
a75b1dde68
commit
5158d53dec
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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/>
|
||||
|
|
Loading…
Reference in New Issue