ntex-mqtt
ntex-mqtt copied to clipboard
PubACK v5 Decoder expect reasonCode+Properties0
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.