mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2025-01-03 05:44:10 -08:00
classlib: fix ByteBuffer,CharBuffer,*Buffer IOOB exception throw with zero length arrays in arguments
fix #713
This commit is contained in:
parent
071a5d90fb
commit
81124a084b
|
@ -67,7 +67,7 @@ public abstract class TByteBuffer extends TBuffer implements TComparable<TByteBu
|
||||||
public abstract TByteBuffer put(int index, byte b);
|
public abstract TByteBuffer put(int index, byte b);
|
||||||
|
|
||||||
public TByteBuffer get(byte[] dst, int offset, int length) {
|
public TByteBuffer get(byte[] dst, int offset, int length) {
|
||||||
if (offset < 0 || offset >= dst.length) {
|
if (offset < 0 || offset > dst.length) {
|
||||||
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + dst.length + ")");
|
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + dst.length + ")");
|
||||||
}
|
}
|
||||||
if (offset + length > dst.length) {
|
if (offset + length > dst.length) {
|
||||||
|
@ -106,7 +106,7 @@ public abstract class TByteBuffer extends TBuffer implements TComparable<TByteBu
|
||||||
if (remaining() < length) {
|
if (remaining() < length) {
|
||||||
throw new TBufferOverflowException();
|
throw new TBufferOverflowException();
|
||||||
}
|
}
|
||||||
if (offset < 0 || offset >= src.length) {
|
if (offset < 0 || offset > src.length) {
|
||||||
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + src.length + ")");
|
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + src.length + ")");
|
||||||
}
|
}
|
||||||
if (offset + length > src.length) {
|
if (offset + length > src.length) {
|
||||||
|
|
|
@ -89,7 +89,7 @@ public abstract class TCharBuffer extends TBuffer implements Comparable<TCharBuf
|
||||||
public abstract TCharBuffer put(int index, char c);
|
public abstract TCharBuffer put(int index, char c);
|
||||||
|
|
||||||
public TCharBuffer get(char[] dst, int offset, int length) {
|
public TCharBuffer get(char[] dst, int offset, int length) {
|
||||||
if (offset < 0 || offset >= dst.length) {
|
if (offset < 0 || offset > dst.length) {
|
||||||
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + dst.length + ")");
|
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + dst.length + ")");
|
||||||
}
|
}
|
||||||
if (offset + length > dst.length) {
|
if (offset + length > dst.length) {
|
||||||
|
@ -138,7 +138,7 @@ public abstract class TCharBuffer extends TBuffer implements Comparable<TCharBuf
|
||||||
if (remaining() < length) {
|
if (remaining() < length) {
|
||||||
throw new TBufferOverflowException();
|
throw new TBufferOverflowException();
|
||||||
}
|
}
|
||||||
if (offset < 0 || offset >= src.length) {
|
if (offset < 0 || offset > src.length) {
|
||||||
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + src.length + ")");
|
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + src.length + ")");
|
||||||
}
|
}
|
||||||
if (offset + length > src.length) {
|
if (offset + length > src.length) {
|
||||||
|
@ -168,7 +168,7 @@ public abstract class TCharBuffer extends TBuffer implements Comparable<TCharBuf
|
||||||
if (remaining() < sz) {
|
if (remaining() < sz) {
|
||||||
throw new TBufferOverflowException();
|
throw new TBufferOverflowException();
|
||||||
}
|
}
|
||||||
if (start < 0 || start >= src.length()) {
|
if (start < 0 || start > src.length()) {
|
||||||
throw new IndexOutOfBoundsException("Start " + start + " is outside of range [0;" + src.length() + ")");
|
throw new IndexOutOfBoundsException("Start " + start + " is outside of range [0;" + src.length() + ")");
|
||||||
}
|
}
|
||||||
if (end > src.length()) {
|
if (end > src.length()) {
|
||||||
|
|
|
@ -56,7 +56,7 @@ public abstract class TDoubleBuffer extends TBuffer implements Comparable<TDoubl
|
||||||
abstract void putElement(int index, double value);
|
abstract void putElement(int index, double value);
|
||||||
|
|
||||||
public TDoubleBuffer get(double[] dst, int offset, int length) {
|
public TDoubleBuffer get(double[] dst, int offset, int length) {
|
||||||
if (offset < 0 || offset >= dst.length) {
|
if (offset < 0 || offset > dst.length) {
|
||||||
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + dst.length + ")");
|
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + dst.length + ")");
|
||||||
}
|
}
|
||||||
if (offset + length > dst.length) {
|
if (offset + length > dst.length) {
|
||||||
|
@ -105,7 +105,7 @@ public abstract class TDoubleBuffer extends TBuffer implements Comparable<TDoubl
|
||||||
if (remaining() < length) {
|
if (remaining() < length) {
|
||||||
throw new TBufferOverflowException();
|
throw new TBufferOverflowException();
|
||||||
}
|
}
|
||||||
if (offset < 0 || offset >= src.length) {
|
if (offset < 0 || offset > src.length) {
|
||||||
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + src.length + ")");
|
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + src.length + ")");
|
||||||
}
|
}
|
||||||
if (offset + length > src.length) {
|
if (offset + length > src.length) {
|
||||||
|
|
|
@ -56,7 +56,7 @@ public abstract class TFloatBuffer extends TBuffer implements Comparable<TFloatB
|
||||||
abstract void putElement(int index, float value);
|
abstract void putElement(int index, float value);
|
||||||
|
|
||||||
public TFloatBuffer get(float[] dst, int offset, int length) {
|
public TFloatBuffer get(float[] dst, int offset, int length) {
|
||||||
if (offset < 0 || offset >= dst.length) {
|
if (offset < 0 || offset > dst.length) {
|
||||||
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + dst.length + ")");
|
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + dst.length + ")");
|
||||||
}
|
}
|
||||||
if (offset + length > dst.length) {
|
if (offset + length > dst.length) {
|
||||||
|
@ -105,7 +105,7 @@ public abstract class TFloatBuffer extends TBuffer implements Comparable<TFloatB
|
||||||
if (remaining() < length) {
|
if (remaining() < length) {
|
||||||
throw new TBufferOverflowException();
|
throw new TBufferOverflowException();
|
||||||
}
|
}
|
||||||
if (offset < 0 || offset >= src.length) {
|
if (offset < 0 || offset > src.length) {
|
||||||
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + src.length + ")");
|
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + src.length + ")");
|
||||||
}
|
}
|
||||||
if (offset + length > src.length) {
|
if (offset + length > src.length) {
|
||||||
|
|
|
@ -56,7 +56,7 @@ public abstract class TIntBuffer extends TBuffer implements Comparable<TIntBuffe
|
||||||
abstract void putElement(int index, int value);
|
abstract void putElement(int index, int value);
|
||||||
|
|
||||||
public TIntBuffer get(int[] dst, int offset, int length) {
|
public TIntBuffer get(int[] dst, int offset, int length) {
|
||||||
if (offset < 0 || offset >= dst.length) {
|
if (offset < 0 || offset > dst.length) {
|
||||||
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + dst.length + ")");
|
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + dst.length + ")");
|
||||||
}
|
}
|
||||||
if (offset + length > dst.length) {
|
if (offset + length > dst.length) {
|
||||||
|
@ -105,7 +105,7 @@ public abstract class TIntBuffer extends TBuffer implements Comparable<TIntBuffe
|
||||||
if (remaining() < length) {
|
if (remaining() < length) {
|
||||||
throw new TBufferOverflowException();
|
throw new TBufferOverflowException();
|
||||||
}
|
}
|
||||||
if (offset < 0 || offset >= src.length) {
|
if (offset < 0 || offset > src.length) {
|
||||||
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + src.length + ")");
|
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + src.length + ")");
|
||||||
}
|
}
|
||||||
if (offset + length > src.length) {
|
if (offset + length > src.length) {
|
||||||
|
|
|
@ -56,7 +56,7 @@ public abstract class TLongBuffer extends TBuffer implements Comparable<TLongBuf
|
||||||
abstract void putElement(int index, long value);
|
abstract void putElement(int index, long value);
|
||||||
|
|
||||||
public TLongBuffer get(long[] dst, int offset, int length) {
|
public TLongBuffer get(long[] dst, int offset, int length) {
|
||||||
if (offset < 0 || offset >= dst.length) {
|
if (offset < 0 || offset > dst.length) {
|
||||||
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + dst.length + ")");
|
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + dst.length + ")");
|
||||||
}
|
}
|
||||||
if (offset + length > dst.length) {
|
if (offset + length > dst.length) {
|
||||||
|
@ -105,7 +105,7 @@ public abstract class TLongBuffer extends TBuffer implements Comparable<TLongBuf
|
||||||
if (remaining() < length) {
|
if (remaining() < length) {
|
||||||
throw new TBufferOverflowException();
|
throw new TBufferOverflowException();
|
||||||
}
|
}
|
||||||
if (offset < 0 || offset >= src.length) {
|
if (offset < 0 || offset > src.length) {
|
||||||
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + src.length + ")");
|
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + src.length + ")");
|
||||||
}
|
}
|
||||||
if (offset + length > src.length) {
|
if (offset + length > src.length) {
|
||||||
|
|
|
@ -56,7 +56,7 @@ public abstract class TShortBuffer extends TBuffer implements Comparable<TShortB
|
||||||
abstract void putElement(int index, short value);
|
abstract void putElement(int index, short value);
|
||||||
|
|
||||||
public TShortBuffer get(short[] dst, int offset, int length) {
|
public TShortBuffer get(short[] dst, int offset, int length) {
|
||||||
if (offset < 0 || offset >= dst.length) {
|
if (offset < 0 || offset > dst.length) {
|
||||||
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + dst.length + ")");
|
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + dst.length + ")");
|
||||||
}
|
}
|
||||||
if (offset + length > dst.length) {
|
if (offset + length > dst.length) {
|
||||||
|
@ -105,7 +105,7 @@ public abstract class TShortBuffer extends TBuffer implements Comparable<TShortB
|
||||||
if (remaining() < length) {
|
if (remaining() < length) {
|
||||||
throw new TBufferOverflowException();
|
throw new TBufferOverflowException();
|
||||||
}
|
}
|
||||||
if (offset < 0 || offset >= src.length) {
|
if (offset < 0 || offset > src.length) {
|
||||||
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + src.length + ")");
|
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + src.length + ")");
|
||||||
}
|
}
|
||||||
if (offset + length > src.length) {
|
if (offset + length > src.length) {
|
||||||
|
|
|
@ -641,4 +641,11 @@ public class ByteBufferTest {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void putGetEmptyArray() {
|
||||||
|
ByteBuffer bb = ByteBuffer.allocate(0);
|
||||||
|
bb.put(new byte[0]);
|
||||||
|
bb.get(new byte[0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -432,4 +432,11 @@ public class CharBufferTest {
|
||||||
buffer.put("TeaVM");
|
buffer.put("TeaVM");
|
||||||
assertThat(buffer.flip().toString(), is("TeaVM"));
|
assertThat(buffer.flip().toString(), is("TeaVM"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void putGetEmptyArray() {
|
||||||
|
CharBuffer cb = CharBuffer.allocate(0);
|
||||||
|
cb.put("");
|
||||||
|
cb.get(new char[0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -372,4 +372,11 @@ public class DoubleBufferTest {
|
||||||
buffer.reset();
|
buffer.reset();
|
||||||
assertThat(buffer.position(), is(1));
|
assertThat(buffer.position(), is(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void putEmptyArray() {
|
||||||
|
DoubleBuffer db = DoubleBuffer.allocate(0);
|
||||||
|
db.put(new double[0]);
|
||||||
|
db.get(new double[0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -372,4 +372,11 @@ public class FloatBufferTest {
|
||||||
buffer.reset();
|
buffer.reset();
|
||||||
assertThat(buffer.position(), is(1));
|
assertThat(buffer.position(), is(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void putEmptyArray() {
|
||||||
|
FloatBuffer fb = FloatBuffer.allocate(0);
|
||||||
|
fb.put(new float[0]);
|
||||||
|
fb.get(new float[0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -386,4 +386,11 @@ public class IntBufferTest {
|
||||||
buffer.reset();
|
buffer.reset();
|
||||||
assertThat(buffer.position(), is(1));
|
assertThat(buffer.position(), is(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void putEmptyArray() {
|
||||||
|
IntBuffer ib = IntBuffer.allocate(0);
|
||||||
|
ib.put(new int[0]);
|
||||||
|
ib.get(new int[0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -372,4 +372,11 @@ public class LongBufferTest {
|
||||||
buffer.reset();
|
buffer.reset();
|
||||||
assertThat(buffer.position(), is(1));
|
assertThat(buffer.position(), is(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void putEmptyArray() {
|
||||||
|
LongBuffer lb = LongBuffer.allocate(0);
|
||||||
|
lb.put(new long[0]);
|
||||||
|
lb.get(new long[0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -372,4 +372,11 @@ public class ShortBufferTest {
|
||||||
buffer.reset();
|
buffer.reset();
|
||||||
assertThat(buffer.position(), is(1));
|
assertThat(buffer.position(), is(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void putEmptyArray() {
|
||||||
|
ShortBuffer sb = ShortBuffer.allocate(0);
|
||||||
|
sb.put(new short[0]);
|
||||||
|
sb.get(new short[0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user