Fix a which could cause data corruption when using AioSocketChannel.

This was because it was possible to have the JDK read into a wrong buffer region if the user called discardReadBytes() later. Fixes #1377
This commit is contained in:
Norman Maurer 2013-05-21 20:19:00 +02:00
parent c1cbe8bec3
commit 548540bc2d

View File

@ -336,6 +336,13 @@ public class AioSocketChannel extends AbstractAioChannel implements SocketChanne
} }
ByteBuf byteBuf = pipeline().inboundByteBuffer(); ByteBuf byteBuf = pipeline().inboundByteBuffer();
// Ensure the readerIndex of the buffer is 0 before beginning an async read.
// Otherwise, JDK can read into a wrong region of the buffer when a handler calls
// discardReadBytes() later, modifying the readerIndex and the writerIndex unexpectedly.
// See https://github.com/netty/netty/issues/1377
byteBuf.discardReadBytes();
expandReadBuffer(byteBuf); expandReadBuffer(byteBuf);
readInProgress = true; readInProgress = true;