shamblett / mqtt5_client

A server and browser based MQTT 5 client for dart
Other
49 stars 25 forks source link

-- mqtt协议解析剩余长度判断不一致,导致解析异常connection 断连 #81

Closed levili-T closed 7 months ago

levili-T commented 7 months ago

MQTT protocol parsing remaining length judgment is inconsistent, resulting in parsing exception connection disconnection

codecov-commenter commented 7 months ago

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (d065797) 61.23% compared to head (144eda3) 61.23%.

Files Patch % Lines
lib/src/utility/mqtt_byte_buffer.dart 0.00% 2 Missing :warning:

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #81 +/- ## ======================================= Coverage 61.23% 61.23% ======================================= Files 102 102 Lines 3555 3555 ======================================= Hits 2177 2177 Misses 1378 1378 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

shamblett commented 7 months ago

Can you explain what you are trying to do here. it looks as though avibytes and availablebytes will have the same value, I'm not following this.

levili-T commented 7 months ago

MqttHeader.fromByteBuffer(this); will move the postion, so after executing this function, availableBytes is the buffer length minus the mqtt fixed header length. _position = position; will reset the position to fromByteBuffer before moving the position. availableBytes becomes the length of the entire buffer, including the length of the mqtt fixed header. You can refer to the processing of MqttMessage.createFrom function to understand

------------------ 原始邮件 ------------------ 发件人: "Steve @.>; 发送时间: 2024年1月13日(星期六) 晚上6:44 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [shamblett/mqtt5_client] -- mqtt协议解析剩余长度判断不一致,导致解析异常connection 断连 (PR #81)

Can you explain what you are trying to do here. it looks as though avibytes and availablebytes will have the same value, I'm not following this.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

levili-T commented 7 months ago

int get availableBytes => length - _position;
and _position = position; // will cause availableBytes add mqtt fix header len if (availableBytes < header.messageSize)

shamblett commented 7 months ago

Yes I see, well spotted, this has been a tricky area in the past, it could probably do with a complete re write. Package re published at version 4.1.0.