Closed ochabloz closed 3 years ago
There is an extra byte in the payload if the length of the property section of a publish packet is greater or equal to 128
How to reproduce the error:
import threading from src.paho.mqtt import client as mqtt from src.paho.mqtt import packettypes url, port, user, pw = "test.mosquitto.org", 1883, "", "" ref_payload = b"abcdefghij" topic = "test/corruption" emitter = mqtt.Client(protocol=mqtt.MQTTv5) emitter.connect(url, port, 120, clean_start=True) emitter.loop_start() recv = mqtt.Client(protocol=mqtt.MQTTv5) recv.connect(url, port, 120, clean_start=True) recv.loop_start() recv.subscribe(topic, qos=2) event = threading.Event() payload = [] def on_message(c, u, m): payload.append(m.payload) event.set() recv.on_message = on_message props = mqtt.Properties(packettypes.PacketTypes.PUBLISH) props.CorrelationData = b"\x00\x00\x00\x01" props.ResponseTopic = "test_bimbibmm/JB007/measurement" props.UserProperty = ("serial_number", "TST") props.UserProperty = ("product_number", "TST") props.UserProperty = ("vrd", "261DAEE5") props.UserProperty = ("timestamp", "1234567.123400") emitter.publish(topic, ref_payload, qos=0, properties=props) event.wait() p = payload.pop() assert ref_payload == p
With the message above, the property section is EXACTLY 128 bytes long. If you remove 1 character from any user property, (p.ex props.UserProperty = ("timestamp", "1234567.12340")) the assertion will then be correct
props.UserProperty = ("timestamp", "1234567.12340")
Thanks very much, that should be fixed now.
Hello @ralight, thanks for your solution and for your reactivity.
There is an extra byte in the payload if the length of the property section of a publish packet is greater or equal to 128
How to reproduce the error:
With the message above, the property section is EXACTLY 128 bytes long. If you remove 1 character from any user property, (p.ex
props.UserProperty = ("timestamp", "1234567.12340")
) the assertion will then be correct