Elffuss BraidHub

kikocis/java-driver public

Ensure decode takes readerIndex() into account.

Motivation:

Frame.Decoder and Frame.Decoder.DecoderForStreamIdSize assume that the passed in ByteBuf always should be read starting at index 0. This is not a safe assumption.

Modifications:

Not start explicit on index 0 but use readerIndex().

Result:

Correctly handle the case where the readerIndex() is not 0.
Changesetc16b0d92503b4ede38a821de8257bf0d86adb48d0a1d358ad196e06ee4220aaa
AuthorNorman Maurer <norman_maurer@apple.com> · 2016-07-11 22:39 +02:00
Committerolim7t <omichallat+github@gmail.com> · 2016-09-15 16:34 -07:00
Parentsdc11f14cdcc4

Browse the files at this changeset

1 file changed

modified driver-core/src/main/java/com/datastax/driver/core/Frame.java +2 −2
@@ -197,7 +197,7 @@
197197 if (buffer.readableBytes() < 1)
198198 return;
199199
200- int version = buffer.getByte(0);
200+ int version = buffer.getByte(buffer.readerIndex());
201201 // version first bit is the "direction" of the frame (request or response)
202202 version = version & 0x7F;
203203
@@ -223,7 +223,7 @@
223223 return null;
224224
225225 // Validate the opcode (this will throw if it's not a response)
226- Message.Response.Type.fromOpcode(buffer.getByte(opcodeOffset));
226+ Message.Response.Type.fromOpcode(buffer.getByte(buffer.readerIndex() + opcodeOffset));
227227
228228 ByteBuf frame = (ByteBuf) super.decode(ctx, buffer);
229229 if (frame == null) {