Skip to content

Commit 1b8c4bb

Browse files
committed
Allow chunks of size 65535
Driver used to only accept chunks of size 32767. This was a limitation on the total chunk size, which includes a 2 byte length header and body. However, Bolt protocol specification allows chunks with body of size 65535 (0xFFFF). This commit fixes the problem by making `ChunkDecoder` accept chunks of size 65535 + 2.
1 parent c5e8da6 commit 1b8c4bb

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

driver/src/main/java/org/neo4j/driver/internal/async/inbound/ChunkDecoder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@
2929

3030
public class ChunkDecoder extends LengthFieldBasedFrameDecoder
3131
{
32-
private static final int MAX_FRAME_LENGTH = Short.MAX_VALUE;
32+
private static final int MAX_FRAME_BODY_LENGTH = 0xFFFF;
3333
private static final int LENGTH_FIELD_OFFSET = 0;
3434
private static final int LENGTH_FIELD_LENGTH = 2;
3535
private static final int LENGTH_ADJUSTMENT = 0;
3636
private static final int INITIAL_BYTES_TO_STRIP = LENGTH_FIELD_LENGTH;
37+
private static final int MAX_FRAME_LENGTH = LENGTH_FIELD_LENGTH + MAX_FRAME_BODY_LENGTH;
3738

3839
private final Logging logging;
3940
private Logger log;

driver/src/test/java/org/neo4j/driver/internal/async/inbound/ChunkDecoderTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,22 @@ public void shouldLogNonEmptyChunkOnTraceLevel()
182182
assertByteBufEquals( wrappedBuffer( bytes ), channel.readInbound() );
183183
}
184184

185+
@Test
186+
public void shouldDecodeMaxSizeChunk()
187+
{
188+
byte[] message = new byte[0xFFFF];
189+
190+
ByteBuf input = buffer();
191+
input.writeShort( message.length ); // chunk header
192+
input.writeBytes( message ); // chunk body
193+
194+
assertTrue( channel.writeInbound( input ) );
195+
assertTrue( channel.finish() );
196+
197+
assertEquals( 1, channel.inboundMessages().size() );
198+
assertByteBufEquals( wrappedBuffer( message ), channel.readInbound() );
199+
}
200+
185201
private static ChunkDecoder newChunkDecoder()
186202
{
187203
return new ChunkDecoder( DEV_NULL_LOGGING );

0 commit comments

Comments
 (0)