sskaje / mqtt

MQTT Client class
https://sskaje.me/category/MQTT/
MIT License
86 stars 33 forks source link

Exception thrown when a PUBLISH message has an particular length #15

Closed dethegeek closed 7 years ago

dethegeek commented 7 years ago

Hi

I discovered when the lib receives a PUBLISH MQTT message with a remaining_length_bytes = 48 an exception is thrown

Exception while listening MQTT messages : 
#0 .../vendor/sskaje/mqtt/mqtt/Message/Base.php(116): sskaje\mqtt\Message\Header\Base->decode('00\x00\x19/5/agent/c3...', 48, 0)
#1 .../vendor/sskaje/mqtt/mqtt/MQTT.php(1318): sskaje\mqtt\Message\Base->decode('00\x00\x19/5/agent/c3...', 48)
#2 .../vendor/sskaje/mqtt/mqtt/MQTT.php(793): sskaje\mqtt\MQTT->message_read()
#3 .../vendor/sskaje/mqtt/mqtt/MQTT.php(779): sskaje\mqtt\MQTT->handle_incoming()
#4 .../vendor/sskaje/mqtt/mqtt/MQTT.php(1135): sskaje\mqtt\MQTT->handle_message()
#5 .../inc/mqttclient.class.php(94): sskaje\mqtt\MQTT->loop()
#6 .../scripts/mqtt.php(37): PluginStorkmdmMqttclient->subscribe()
#7 {main}

Notice the remaining length equals the first byte of the message (PUBLISH). Because the first byte and the second bytes are the same, the strpos reports the position of the first byte instead of the second, and it does not matches $pos.

dethegeek commented 7 years ago

An example of cli to trigger the exception

mosquitto_pub -t "/a/agent/azertyui/gsdfghj" -m '{"query":"Inventory"}'
sskaje commented 7 years ago

Merged, thanks again.