GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Merge commit from fork · netty/netty@82f47fa

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • codec-mqtt/src/main/java/io/netty/handler/codec/mqtt
    • MqttDecoder.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttDecoder.java‎

Copy file name to clipboardExpand all lines: codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttDecoder.java
+21-2Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import io.netty.handler.codec.mqtt.MqttDecoder.DecoderState;
2525
import io.netty.handler.codec.mqtt.MqttProperties.IntegerProperty;
2626
import io.netty.util.CharsetUtil;
27+
import io.netty.util.Signal;
2728
import io.netty.util.internal.ObjectUtil;
2829

2930
import java.util.ArrayList;
@@ -123,8 +124,22 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> ou
123124

124125
case READ_VARIABLE_HEADER: try {
125126
int bytesRemainingBeforeVariableHeader = bytesRemainingInVariablePart;
126-
variableHeader = decodeVariableHeader(ctx, buffer, mqttFixedHeader);
127-
if (bytesRemainingBeforeVariableHeader > maxBytesInMessage) {
127+
int initialAvailableBytes = buffer.readableBytes();
128+
boolean bailOut = false;
129+
try {
130+
variableHeader = decodeVariableHeader(ctx, buffer, mqttFixedHeader);
131+
} catch (Signal signal) {
132+
if (initialAvailableBytes < maxBytesInMessage) {
133+
// Ask for REPLAY if the buffer was less than maxBytesInMessage
134+
throw signal;
135+
} else {
136+
// We couldn't parse the complete message, and it's already too large.
137+
// Swallow the Signal (we don't need more data) and instead bail out
138+
// and throw the TooLongFrameException below.
139+
bailOut = true;
140+
}
141+
}
142+
if (bailOut || bytesRemainingBeforeVariableHeader > maxBytesInMessage) {
128143
buffer.skipBytes(actualReadableBytes());
129144
throw new TooLongFrameException("message length exceeds " + maxBytesInMessage + ": "
130145
+ bytesRemainingBeforeVariableHeader);
@@ -762,6 +777,10 @@ private static Result<MqttProperties> decodeProperties(ByteBuf buffer) {
762777
final long propertiesLength = decodeVariableByteInteger(buffer);
763778
int totalPropertiesLength = unpackA(propertiesLength);
764779
int numberOfBytesConsumed = unpackB(propertiesLength);
780+
if (buffer.readableBytes() < totalPropertiesLength) {
781+
// Force an early REPLAY to avoid repeatedly parsing the properties.
782+
buffer.readSlice(totalPropertiesLength);
783+
}
765784

766785
MqttProperties decodedProperties = new MqttProperties();
767786
while (numberOfBytesConsumed < totalPropertiesLength) {

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.