Skip to content

MqttDecoder accepts malformed PINGREQ with non-zero Remaining Length #16851

@shblue21

Description

@shblue21

Expected behavior

This input appears to be a malformed PINGREQ, not a valid PINGREQ followed
by a PINGRESP:

C0 02 D0 00

C0 02 is PINGREQ with Remaining Length 2. PINGREQ has no variable
header or payload, so its Remaining Length must be 0 in both MQTT 3.1.1 and
MQTT 5.0:

The trailing D0 00 bytes are still inside the malformed PINGREQ frame.
Remaining Length defines the boundary of the current MQTT packet, so those bytes
should not start another packet.

Expected result: one failed MqttMessage for the malformed PINGREQ.

Actual behavior

MqttDecoder can decode the same input as a valid PINGREQ, then a valid
PINGRESP.

The decoder reaches the default branch in decodePayload for messages with no
payload, and returns null without checking that bytesRemainingInVariablePart
is zero. The same path is used by other MQTT message types with no payload, so
this is not specific to PINGREQ.

Netty version

4.1.x, 4.2.x, and 5.0.x.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions