Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is an extra Byte in the payload if the properties packet length is greater or equal to 128 #541

Closed
ochabloz opened this issue Dec 14, 2020 · 2 comments · Fixed by home-assistant/core#59339

Comments

@ochabloz
Copy link

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

@ralight
Copy link
Contributor

ralight commented Dec 14, 2020

Thanks very much, that should be fixed now.

@ochabloz
Copy link
Author

Hello @ralight, thanks for your solution and for your reactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants