Skip to content

Fix ReadPackedUInt32 unbounded varint decode (max 5 bytes)#70

Open
NikoCat233 wants to merge 1 commit into
willardf:mainfrom
NikoCat233:fix/ReadPackedUInt32-limit
Open

Fix ReadPackedUInt32 unbounded varint decode (max 5 bytes)#70
NikoCat233 wants to merge 1 commit into
willardf:mainfrom
NikoCat233:fix/ReadPackedUInt32-limit

Conversation

@NikoCat233

Copy link
Copy Markdown

ReadPackedUInt32 looped while the high bit was set with no byte/shift cap. Although BytesRemaining bounds runtime, encodings longer than 5 bytes are invalid for uint and can wrap under C# shift masking (shift >= 32), producing unexpected "valid" values for upper layers.

  • Rewrite MessageReader.ReadPackedUInt32 with a hard 5-byte loop.
  • Reject a continuation bit on the 5th byte.
  • Reject 5th-byte payload bits above 0x0F so decoded values stay in UInt32 range.
  • Add unit tests for max value, overlong encodings, and out-of-range fifth bytes.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant