Fix: restrict Variable Byte Integer to 24bits #90
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.
The MQTT 5.0 specification defines Variable Byte Integer as a maximum of 24 bits. The 3.x spec uses this format for packet length only but in 5.0 it is also used in properties (e.g. subscriptionIdentifier)
Testing generation of a Variable Byte Integer with anything bigger than that resulted in a
Attempt to write outside buffer bounds
error because numbers.js would allocate 0 bytes and still try to write 4 or more bytes.Parsing of a Variable Byte Integer (e.g. in packet length) > 24 bits would not emit an error where it should.
This PR fixes that and adds tests to confirm 24 bits maximum.
It also renames the constants and variables used by the parser so they are inline with its intended use again.
Performance should not be impacted because:
a) generator algorithm has been simplified so it should be a tiny bit faster
b) the cache hides the performance of generation anyway :-)
c) the rest of the changes are only small logic updates
Kind regards,
Hans