Fix bitwise operation in readUnsignedVarInt
#17
Merged
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.
Problem
Method
VarInt::readUnsignedLong()works incorrectly due to an bug in C functionreadUnsignedVarInt.Description
The method reads the first 4 bytes (while bitwise shift is less than 32), and ignores the rest.
This is happens because of the compiler makes implicit cast of
unsigned chartointin bitwise shift operation. An integer value is shifted by7 * 5 (35)bits and more, so it becomes corrupted.Reproducing
Code using
ext-encoding:Output:
Code using
pocketmine/binaryutils:Output:
And the
pocketmine/binaryutilsresult is right, theext-encodingresult is wrong.Solution
Add explicit cast of
unsigned charto typeTValuein evaluations withbytevariable inreadUnsignedVarInt.