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
d22a35628d
commit
c32c520edd
@ -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;
|
||||
|
@ -334,6 +334,8 @@ public class MqttCodecTest {
|
||||
|
||||
assertEquals("Expected one object but got " + out.size(), 1, out.size());
|
||||
|
||||
assertEquals(0, byteBuf.readableBytes());
|
||||
|
||||
final MqttMessage decodedMessage = (MqttMessage) out.get(0);
|
||||
|
||||
validateFixedHeaders(message.fixedHeader(), decodedMessage.fixedHeader());
|
||||
@ -356,6 +358,8 @@ public class MqttCodecTest {
|
||||
|
||||
assertEquals("Expected one object but got " + out.size(), 1, out.size());
|
||||
|
||||
assertEquals(0, byteBuf.readableBytes());
|
||||
|
||||
final MqttMessage decodedMessage = (MqttMessage) out.get(0);
|
||||
|
||||
validateFixedHeaders(message.fixedHeader(), decodedMessage.fixedHeader());
|
||||
@ -378,6 +382,8 @@ public class MqttCodecTest {
|
||||
|
||||
assertEquals("Expected one object but got " + out.size(), 1, out.size());
|
||||
|
||||
assertEquals(0, byteBuf.readableBytes());
|
||||
|
||||
final MqttMessage decodedMessage = (MqttMessage) out.get(0);
|
||||
validateFixedHeaders(message.fixedHeader(), decodedMessage.fixedHeader());
|
||||
validateDecoderExceptionTooLargeMessage(decodedMessage);
|
||||
@ -397,6 +403,8 @@ public class MqttCodecTest {
|
||||
|
||||
assertEquals("Expected one object but got " + out.size(), 1, out.size());
|
||||
|
||||
assertEquals(0, byteBuf.readableBytes());
|
||||
|
||||
final MqttMessage decodedMessage = (MqttMessage) out.get(0);
|
||||
|
||||
validateFixedHeaders(message.fixedHeader(), decodedMessage.fixedHeader());
|
||||
@ -419,6 +427,8 @@ public class MqttCodecTest {
|
||||
|
||||
assertEquals("Expected one object but got " + out.size(), 1, out.size());
|
||||
|
||||
assertEquals(0, byteBuf.readableBytes());
|
||||
|
||||
final MqttMessage decodedMessage = (MqttMessage) out.get(0);
|
||||
validateFixedHeaders(message.fixedHeader(), decodedMessage.fixedHeader());
|
||||
validateMessageIdVariableHeader(message.variableHeader(),
|
||||
@ -440,6 +450,8 @@ public class MqttCodecTest {
|
||||
|
||||
assertEquals("Expected one object but got " + out.size(), 1, out.size());
|
||||
|
||||
assertEquals(0, byteBuf.readableBytes());
|
||||
|
||||
final MqttMessage decodedMessage = (MqttMessage) out.get(0);
|
||||
validateFixedHeaders(message.fixedHeader(), decodedMessage.fixedHeader());
|
||||
validateMessageIdVariableHeader(message.variableHeader(),
|
||||
@ -461,6 +473,8 @@ public class MqttCodecTest {
|
||||
|
||||
assertEquals("Expected one object but got " + out.size(), 1, out.size());
|
||||
|
||||
assertEquals(0, byteBuf.readableBytes());
|
||||
|
||||
final MqttMessage decodedMessage = (MqttMessage) out.get(0);
|
||||
validateFixedHeaders(message.fixedHeader(), decodedMessage.fixedHeader());
|
||||
validateMessageIdVariableHeader(message.variableHeader(),
|
||||
|
Loading…
Reference in New Issue
Block a user