Fix ReadPackedUInt32 unbounded varint decode (max 5 bytes)#70
Open
NikoCat233 wants to merge 1 commit into
Open
Fix ReadPackedUInt32 unbounded varint decode (max 5 bytes)#70NikoCat233 wants to merge 1 commit into
NikoCat233 wants to merge 1 commit into
Conversation
ReadPackedUInt32 previously kept consuming continuation bytes until the stream ended. A uint varint is at most 5 bytes; longer encodings wrap under C# uint shift semantics and can decode to unexpected values. Rewrite the decoder to: - read at most 5 bytes - reject a continuation bit on the 5th byte - reject 5th-byte data above 0x0F so the value stays in UInt32 range Add unit tests for uint.MaxValue, overlong encodings, and out-of-range 5th-byte payloads.
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.
ReadPackedUInt32looped while the high bit was set with no byte/shift cap. AlthoughBytesRemainingbounds runtime, encodings longer than 5 bytes are invalid foruintand can wrap under C# shift masking (shift >= 32), producing unexpected "valid" values for upper layers.MessageReader.ReadPackedUInt32with a hard 5-byte loop.0x0Fso decoded values stay inUInt32range.