Fix bitwise operation in readUnsignedVarInt#17
Merged
dktapps merged 7 commits intopmmp:masterfrom Jun 21, 2025
Merged
Conversation
Adds explicit cast of unsigned char to TValue. Analyzer mistakenly implicitly casted unsigned char to 32-bit integer that led to byte loss.
Member
|
Please add a .phpt test to verify the issue |
Contributor
Author
|
Added |
dktapps
reviewed
Jun 20, 2025
Member
|
Verified locally, this is good to merge once the build passes 👍🏻 |
dktapps
reviewed
Jun 21, 2025
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.
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.