mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-03 17:54:13 +00:00
[Java] Flexbuffers - Negative signed object length (#6651)
* retry with correct email * update JavaTest.java
This commit is contained in:
@@ -655,7 +655,7 @@ public class FlexBuffers {
|
|||||||
|
|
||||||
Sized(ReadBuf buff, int end, int byteWidth) {
|
Sized(ReadBuf buff, int end, int byteWidth) {
|
||||||
super(buff, end, byteWidth);
|
super(buff, end, byteWidth);
|
||||||
size = readInt(bb, end - byteWidth, byteWidth);
|
size = (int) readUInt(bb, end - byteWidth, byteWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int size() {
|
public int size() {
|
||||||
|
|||||||
@@ -862,6 +862,27 @@ class JavaTest {
|
|||||||
TestEq((byte)-1, result[3]);
|
TestEq((byte)-1, result[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void testSingleElementLongBlob() {
|
||||||
|
|
||||||
|
// verifies blobs of up to 2^16 in length
|
||||||
|
for (int i = 2; i <= 1<<16; i = i<<1) {
|
||||||
|
byte[] input = new byte[i-1];
|
||||||
|
for (int index = 0; index < input.length; index++) {
|
||||||
|
input[index] = (byte)(index % 64);
|
||||||
|
}
|
||||||
|
|
||||||
|
FlexBuffersBuilder builder = new FlexBuffersBuilder();
|
||||||
|
builder.putBlob(input);
|
||||||
|
ByteBuffer b = builder.finish();
|
||||||
|
FlexBuffers.Reference r = FlexBuffers.getRoot(b);
|
||||||
|
byte[] result = r.asBlob().getBytes();
|
||||||
|
|
||||||
|
for (int index = 0; index < input.length; index++) {
|
||||||
|
TestEq((byte)(index % 64), result[index]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void testSingleElementUByte() {
|
public static void testSingleElementUByte() {
|
||||||
FlexBuffersBuilder builder = new FlexBuffersBuilder();
|
FlexBuffersBuilder builder = new FlexBuffersBuilder();
|
||||||
builder.putUInt(0xFF);
|
builder.putUInt(0xFF);
|
||||||
@@ -1084,6 +1105,7 @@ class JavaTest {
|
|||||||
testSingleElementSmallString();
|
testSingleElementSmallString();
|
||||||
testSingleElementBigString();
|
testSingleElementBigString();
|
||||||
testSingleElementBlob();
|
testSingleElementBlob();
|
||||||
|
testSingleElementLongBlob();
|
||||||
testSingleElementVector();
|
testSingleElementVector();
|
||||||
testSingleFixedTypeVector();
|
testSingleFixedTypeVector();
|
||||||
testSingleElementUShort();
|
testSingleElementUShort();
|
||||||
|
|||||||
Reference in New Issue
Block a user