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:
parent
c1cbe8bec3
commit
548540bc2d
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user