GeezerVison is showing github.com — MQTT: Make the decodeProperties early-REPLAY check actually fire (#16… · netty/netty@2d781e2
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 |
|---|
@@ -749,9 +749,14 @@ private static Result<MqttProperties> decodeProperties(ByteBuf buffer) { |
749 | 749 | final long propertiesLength = decodeVariableByteInteger(buffer); |
750 | 750 | int totalPropertiesLength = unpackA(propertiesLength); |
751 | 751 | int numberOfBytesConsumed = unpackB(propertiesLength); |
752 | | - if (buffer.readableBytes() < totalPropertiesLength) { |
753 | | - // Force an early REPLAY to avoid repeatedly parsing the properties. |
754 | | - buffer.readSlice(totalPropertiesLength); |
| 752 | + if (totalPropertiesLength > 0) { |
| 753 | + // Force an early REPLAY when the buffer does not yet have the full properties block, |
| 754 | + // so we don't repeatedly parse partial properties as data arrives. A direct |
| 755 | + // buffer.readableBytes() check is unusable here because ReplayingDecoderByteBuf |
| 756 | + // returns Integer.MAX_VALUE - readerIndex; touching the last byte via getByte() |
| 757 | + // routes through ReplayingDecoderByteBuf.checkIndex(), which throws REPLAY if the |
| 758 | + // buffer's writerIndex hasn't reached that position yet. |
| 759 | + buffer.getByte(buffer.readerIndex() + totalPropertiesLength - 1); |
755 | 760 | } |
756 | 761 |
|
757 | 762 | MqttProperties decodedProperties = new MqttProperties(); |
|