ntex-mqtt icon indicating copy to clipboard operation
ntex-mqtt copied to clipboard

PubACK v5 Decoder expect reasonCode+Properties0

Open gajanak opened this issue 3 years ago • 0 comments

Hello,

on evaluating your library I noticed some weired behavior. I try to explain what noticed and what expected in src\v5\codec\packet\pubacks.rs PublishAck::decode The Decoder expects that reason code and properties are present or absent. (The same I would interpret the MQTT specification)

I tested with different MQTT Brokers and notices then every server or Client I found allows ReasonCode != 0 to add, but dont send 0 for propertyLength. This Results in a remaining of 3. ( id(2) + reason(1) ) The Code expect 2 ( id(2) or 4 ( id(2)+reason(1)+length(1) ).

My Question: is this a Bug or a Feature ?

My Rust Knowledge is to low, so this is only a test to fix :

impl PublishAck {
    pub(crate) fn decode(src: &mut Bytes) -> Result<Self, DecodeError> {
        let packet_id = NonZeroU16::decode(src)?;
        let (reason_code, properties, reason_string) = if src.has_remaining() {
            let reason_code = src.get_u8().try_into()?;
            let (properties, reason_string) = if src.has_remaining() { // accept missing properties
                ack_props::decode(src)?
            } else {
                (UserProperties::default(), None)
            };
            ensure!(!src.has_remaining(), DecodeError::InvalidLength); // no bytes should be left
            (reason_code, properties, reason_string)
        } else {
            (PublishAckReason::Success, UserProperties::default(), None)
        };

        Ok(Self { packet_id, reason_code, properties, reason_string })
    }

Perhaps this helps someone.... I don't know if this is a Bug or not.

gajanak avatar Jul 25 '21 11:07 gajanak