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 — Auto-port 4.2: MQTT: Reject malformed no-payload packets with non-zer… · netty/netty@2394530

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
    • test/java/io/netty/handler/codec/mqtt
      • MqttCodecTest.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
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,11 @@ private Object decodePayload(
540540
return decodePublishPayload(buffer);
541541

542542
default:
543-
// unknown payload , no byte consumed
543+
// No payload for this message type. If the fixed header's Remaining Length
544+
// claimed bytes beyond what the variable header consumed (e.g. a PINGREQ
545+
// with non-zero Remaining Length), the frame is malformed.
546+
// See https://github.com/netty/netty/issues/16851
547+
validateNoBytesRemain(0);
544548
return null;
545549
}
546550
}
Collapse file

‎codec-mqtt/src/test/java/io/netty/handler/codec/mqtt/MqttCodecTest.java‎

Copy file name to clipboardExpand all lines: codec-mqtt/src/test/java/io/netty/handler/codec/mqtt/MqttCodecTest.java
+35Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,41 @@ public void testDisconnectMessage() throws Exception {
517517
testMessageWithOnlyFixedHeader(MqttMessage.DISCONNECT);
518518
}
519519

520+
@Test
521+
public void testPingReqWithNonZeroRemainingLengthIsRejected() throws Exception {
522+
// Regression for https://github.com/netty/netty/issues/16851: PINGREQ is a 2-byte
523+
// fixed-header-only packet (0xC0 0x00). The bytes below claim Remaining Length 2,
524+
// which makes the trailing 0xD0 0x00 part of the same (malformed) PINGREQ frame
525+
// rather than a separate PINGRESP. The decoder must reject this as one invalid
526+
// message rather than silently accept two.
527+
EmbeddedChannel channel = new EmbeddedChannel(new MqttDecoder());
528+
ByteBuf byteBuf = channel.alloc().buffer();
529+
// Fixed header byte 1: PINGREQ (type 12), all flags 0.
530+
byteBuf.writeByte(0xC0);
531+
// Remaining Length 2 - invalid per MQTT 3.1.1 / 5.0 spec (PINGREQ has no variable
532+
// header or payload, so Remaining Length must be 0).
533+
byteBuf.writeByte(0x02);
534+
// Two leftover bytes still inside the malformed packet's frame:
535+
byteBuf.writeByte(0xD0);
536+
byteBuf.writeByte(0x00);
537+
538+
try {
539+
assertTrue(channel.writeInbound(byteBuf));
540+
MqttMessage first = channel.readInbound();
541+
try {
542+
assertTrue(first.decoderResult().isFailure(),
543+
"expected a failed message for the malformed PINGREQ");
544+
assertInstanceOf(DecoderException.class, first.decoderResult().cause());
545+
} finally {
546+
ReferenceCountUtil.release(first);
547+
}
548+
// No second message: the trailing bytes belong to the malformed frame.
549+
assertNull(channel.readInbound());
550+
} finally {
551+
assertFalse(channel.finishAndReleaseAll());
552+
}
553+
}
554+
520555
//All 0..F message type codes are valid in MQTT 5
521556
@Test
522557
public void testUnknownMessageType() throws Exception {

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.