Before throwing TooLongFrameException,should skip the bytes to be read in MqttDecoder (#11204)
Motivation: Before throwing TooLongFrameException, should call the skipBytes method to skip the bytes to be read Modification: - skip bytes before throw Result: Actually skip the bytes when we detect too much data Signed-off-by: xingrufei <xingrufei@sogou-inc.com> Co-authored-by: xingrufei <xingrufei@sogou-inc.com>
This commit is contained in:
parent
438632a3ac
commit
bf721c84f4
@ -98,6 +98,7 @@ public final class MqttDecoder extends ReplayingDecoder<DecoderState> {
|
||||
final Result<?> decodedVariableHeader = decodeVariableHeader(ctx, buffer, mqttFixedHeader);
|
||||
variableHeader = decodedVariableHeader.value;
|
||||
if (bytesRemainingInVariablePart > maxBytesInMessage) {
|
||||
buffer.skipBytes(buffer.readableBytes());
|
||||
throw new TooLongFrameException("too large message: " + bytesRemainingInVariablePart + " bytes");
|
||||
}
|
||||
bytesRemainingInVariablePart -= decodedVariableHeader.numberOfBytesConsumed;
|
||||
|
@ -327,6 +327,7 @@ public class MqttCodecTest {
|
||||
verify(ctx).fireChannelRead(captor.capture());
|
||||
|
||||
final MqttMessage decodedMessage = captor.getValue();
|
||||
assertEquals(0, byteBuf.readableBytes());
|
||||
|
||||
validateFixedHeaders(message.fixedHeader(), decodedMessage.fixedHeader());
|
||||
validateConnectVariableHeader(message.variableHeader(),
|
||||
@ -348,6 +349,7 @@ public class MqttCodecTest {
|
||||
verify(ctx).fireChannelRead(captor.capture());
|
||||
|
||||
final MqttMessage decodedMessage = captor.getValue();
|
||||
assertEquals(0, byteBuf.readableBytes());
|
||||
|
||||
validateFixedHeaders(message.fixedHeader(), decodedMessage.fixedHeader());
|
||||
validateConnectVariableHeader(message.variableHeader(),
|
||||
@ -369,6 +371,8 @@ public class MqttCodecTest {
|
||||
verify(ctx).fireChannelRead(captor.capture());
|
||||
|
||||
final MqttMessage decodedMessage = captor.getValue();
|
||||
assertEquals(0, byteBuf.readableBytes());
|
||||
|
||||
validateFixedHeaders(message.fixedHeader(), decodedMessage.fixedHeader());
|
||||
validateDecoderExceptionTooLargeMessage(decodedMessage);
|
||||
} finally {
|
||||
@ -387,6 +391,7 @@ public class MqttCodecTest {
|
||||
verify(ctx).fireChannelRead(captor.capture());
|
||||
|
||||
final MqttMessage decodedMessage = captor.getValue();
|
||||
assertEquals(0, byteBuf.readableBytes());
|
||||
|
||||
validateFixedHeaders(message.fixedHeader(), decodedMessage.fixedHeader());
|
||||
validatePublishVariableHeader(message.variableHeader(),
|
||||
@ -408,6 +413,8 @@ public class MqttCodecTest {
|
||||
verify(ctx).fireChannelRead(captor.capture());
|
||||
|
||||
final MqttMessage decodedMessage = captor.getValue();
|
||||
assertEquals(0, byteBuf.readableBytes());
|
||||
|
||||
validateFixedHeaders(message.fixedHeader(), decodedMessage.fixedHeader());
|
||||
validateMessageIdVariableHeader(message.variableHeader(),
|
||||
(MqttMessageIdVariableHeader) decodedMessage.variableHeader());
|
||||
@ -428,6 +435,8 @@ public class MqttCodecTest {
|
||||
verify(ctx).fireChannelRead(captor.capture());
|
||||
|
||||
final MqttMessage decodedMessage = captor.getValue();
|
||||
assertEquals(0, byteBuf.readableBytes());
|
||||
|
||||
validateFixedHeaders(message.fixedHeader(), decodedMessage.fixedHeader());
|
||||
validateMessageIdVariableHeader(message.variableHeader(),
|
||||
(MqttMessageIdVariableHeader) decodedMessage.variableHeader());
|
||||
@ -448,6 +457,8 @@ public class MqttCodecTest {
|
||||
verify(ctx).fireChannelRead(captor.capture());
|
||||
|
||||
final MqttMessage decodedMessage = captor.getValue();
|
||||
assertEquals(0, byteBuf.readableBytes());
|
||||
|
||||
validateFixedHeaders(message.fixedHeader(), decodedMessage.fixedHeader());
|
||||
validateMessageIdVariableHeader(message.variableHeader(),
|
||||
(MqttMessageIdVariableHeader) decodedMessage.variableHeader());
|
||||
|
Loading…
Reference in New Issue
Block a user