Skip to content

Commit 0fad7cc

Browse files
authored
Take into account the return value of TcpTransport.readMessageLength(...) in Netty4SizeHeaderFrameDecoder
(#31057)
1 parent 03dcf22 commit 0fad7cc

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4SizeHeaderFrameDecoder.java

+11-9
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,19 @@ final class Netty4SizeHeaderFrameDecoder extends ByteToMessageDecoder {
3737
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
3838
try {
3939
BytesReference networkBytes = Netty4Utils.toBytesReference(in);
40-
int messageLength = TcpTransport.readMessageLength(networkBytes) + HEADER_SIZE;
41-
// If the message length is -1, we have not read a complete header. If the message length is
42-
// greater than the network bytes available, we have not read a complete frame.
43-
if (messageLength != -1 && messageLength <= networkBytes.length()) {
44-
final ByteBuf message = in.skipBytes(HEADER_SIZE);
45-
// 6 bytes would mean it is a ping. And we should ignore.
46-
if (messageLength != 6) {
47-
out.add(message);
40+
int messageLength = TcpTransport.readMessageLength(networkBytes);
41+
// If the message length is -1, we have not read a complete header.
42+
if (messageLength != -1) {
43+
int messageLengthWithHeader = messageLength + HEADER_SIZE;
44+
// If the message length is greater than the network bytes available, we have not read a complete frame.
45+
if (messageLengthWithHeader <= networkBytes.length()) {
46+
final ByteBuf message = in.skipBytes(HEADER_SIZE);
47+
// 6 bytes would mean it is a ping. And we should ignore.
48+
if (messageLengthWithHeader != 6) {
49+
out.add(message);
50+
}
4851
}
4952
}
50-
5153
} catch (IllegalArgumentException ex) {
5254
throw new TooLongFrameException(ex);
5355
}

0 commit comments

Comments
 (0)