Skip to content

Incorrect remaining length is calculated when topic contains utf-8-3 or utf-8-4 characters in SUBSCRIBE/PUBLISH packets #90

Closed
@Eason010212

Description

@Eason010212

Current version of adafruit_minimqtt.py uses len() method to calculate a packet's remaining length, for example:

packet_length += sum(len(topic) for topic, qos in topics)
remaining_length = 2 + len(msg) + len(topic)

As shown above, strings are measured instead of UTF-8 bytes. When a topic only contains English characters, numbers and punctuation marks, the calculation result is correct; However, when it contains some utf-8-3 or utf-8-4 characters (such as Chinese characters) , an incorrect calculation result of remaining length will be obtained. For example, the actual encoding length of "中文" should be 6, while the length calculated by len() is 2. As a result, such packets will be rejected by any MQTT server.

In MQTT protocol, there is no restriction on utf-8-3 or utf-8-4 characters, so I think this issue is probably a bug that needs to be fixed.

At present, in the application I developed, I rewrite the len() method to temporarily solve this problem, but I still hope that the developers of this library can make official bug fixes.

Thank you very much.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions