GeezerVison is showing github.com — Auto-port 4.2: MQTT: Make the decodeProperties early-REPLAY check act… · netty/netty@bfbdc4e
File tree
Expand file treeCollapse file tree
Open diff view settings
codec-mqtt/src/main/java/io/netty/handler/codec/mqtt
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttDecoder.java +8-3Lines changed: 8 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -780,9 +780,14 @@ private static Result<MqttProperties> decodeProperties(ByteBuf buffer) { |
780 | 780 | final long propertiesLength = decodeVariableByteInteger(buffer); |
781 | 781 | int totalPropertiesLength = unpackA(propertiesLength); |
782 | 782 | int numberOfBytesConsumed = unpackB(propertiesLength); |
783 | | - if (buffer.readableBytes() < totalPropertiesLength) { |
784 | | - // Force an early REPLAY to avoid repeatedly parsing the properties. |
785 | | - buffer.readSlice(totalPropertiesLength); |
| 783 | + if (totalPropertiesLength > 0) { |
| 784 | + // Force an early REPLAY when the buffer does not yet have the full properties block, |
| 785 | + // so we don't repeatedly parse partial properties as data arrives. A direct |
| 786 | + // buffer.readableBytes() check is unusable here because ReplayingDecoderByteBuf |
| 787 | + // returns Integer.MAX_VALUE - readerIndex; touching the last byte via getByte() |
| 788 | + // routes through ReplayingDecoderByteBuf.checkIndex(), which throws REPLAY if the |
| 789 | + // buffer's writerIndex hasn't reached that position yet. |
| 790 | + buffer.getByte(buffer.readerIndex() + totalPropertiesLength - 1); |
786 | 791 | } |
787 | 792 |
|
788 | 793 | MqttProperties decodedProperties = new MqttProperties(); |
|