Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.apache.fory.platform.AndroidSupport;
import org.apache.fory.platform.JdkVersion;
import org.apache.fory.platform.internal._UnsafeUtils;
import sun.misc.Unsafe;

Check warning on line 35 in java/fory-core/src/main/java/org/apache/fory/memory/MemoryBuffer.java

View workflow job for this annotation

GitHub Actions / Kotlin Xlang Test

sun.misc.Unsafe is internal proprietary API and may be removed in a future release

Check warning on line 35 in java/fory-core/src/main/java/org/apache/fory/memory/MemoryBuffer.java

View workflow job for this annotation

GitHub Actions / Kotlin Xlang Test

sun.misc.Unsafe is internal proprietary API and may be removed in a future release

/**
* A class for operations on memory managed by Fory. The buffer may be backed by heap memory (byte
Expand Down Expand Up @@ -3907,6 +3907,7 @@
if (diff < binarySize) {
streamReader.fillBuffer(binarySize - diff);
}
readerIndex = readIdx;
return binarySize;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3298,6 +3298,7 @@ private int continueReadBinarySize(int readIdx, int bulkRead, int binarySize) {
if (diff < binarySize) {
streamReader.fillBuffer(binarySize - diff);
}
readerIndex = readIdx;
return binarySize;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,25 @@ public void testWritePrimitiveArrayWithSizeEmbedded() {
assertEquals(chars, readChars);
}

@Test
public void testReadBytesAndSizeLargePrefix() {
// Lengths that need 3-byte (>= 2^14) and 4-byte (>= 2^21) varint prefixes. The 3/4-byte
// prefix path must advance readerIndex past the prefix, otherwise readBytesAndSize() returns
// the prefix bytes shifted into the payload body.
Random random = new Random(42);
for (int len : new int[] {16_384, 16_385, 25_000, 2_097_152, 2_097_153}) {
MemoryBuffer buf = MemoryUtils.buffer(len + 64);
byte[] expected = new byte[len];
random.nextBytes(expected);
buf.writeBytesWithSize(expected);
// Trailing payload: verifies the reader index is aligned for subsequent reads.
buf.writeInt32(0x12345678);
byte[] actual = buf.readBytesAndSize();
assertEquals(expected, actual);
assertEquals(0x12345678, buf.readInt32());
}
}

@Test
public void testReadCharsAndSizeAlignment() {
MemoryBuffer buf = MemoryUtils.buffer(8);
Expand Down
Loading