Fix MQTT v5.0 "beyond size" error in PUBACK parsing#53
Merged
Conversation
Contributor
Author
|
Here's a link to the corresponding PR in the other repository: Tieske#8 |
Owner
|
Thanks @haukepribnow |
Owner
|
@haukepribnow , I've merged your pull request. Thanks! |
Contributor
FYI; You can use luarocks. Use |
Contributor
Contributor
|
@haukepribnow LuaMQTTT fix is up on LuaRocks; t1.0.4 (in case you use that fork) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses a protocol parsing error in the MQTT v5.0 implementation where certain PUBACK packets would trigger a "beyond size" error and a subsequent connection drop.
The issue was identified during a late-night debugging session involving my MQTT broker that omit the Optional Properties section in 3-byte packets (Packet ID + Reason Code).
Technical Context
Per MQTT v5.0 Specification (Section 3.4.2), the Variable Header for PUBACK is flexible in length:
Specifically, Section 3.4.2.2.1 (Property Length) states:
The length of the Properties in the PUBACK packet Variable Header encoded as a Variable Byte Integer. If the Remaining Length is less than 4 there is no Property Length and the value of 0 is used.
The existing logic correctly checked
input.available > 0before parsing the Reason Code. However, it failed to perform a subsequent check before callingparse_properties. If a broker sends exactly 3 bytes, the parser attempts to read a "Property Length" byte that does not exist according to the spec, resulting in a fatal buffer error.Scope of Changes
pubrec,pubrel,pubcomp, andunsuback. Due to time constraints, I am only submitting the fix forpubackat this time as it was the specific blocker for my environment. I likely will not have the bandwidth to address the others in the near future; I invite any interested contributors to apply this same logic to the remaining functions inprotocol5.lua.Repository & History Strategy
I am raising this PR in both xHasKx/luamqtt and Tieske/luamqtt.
To maintain structural integrity across repository boundaries:
Cross-Reference: I will add a link to the corresponding PR in the comments once both have been successfully created.