[Core/Proto] Fix VarInt negative value encoding and MultiMsg recursion#84
Open
citydirector wants to merge 10 commits intoLagrangeDev:mainfrom
Open
[Core/Proto] Fix VarInt negative value encoding and MultiMsg recursion#84citydirector wants to merge 10 commits intoLagrangeDev:mainfrom
citydirector wants to merge 10 commits intoLagrangeDev:mainfrom
Conversation
Previously, MultiMsgEntity only uploaded the outer container but failed to upload internal entities (like images), causing empty MsgInfo and -400 errors. This fix ensures all internal entities are recursively preprocessed using the parent message context.
This PR fixes two critical issues related to negative integer handling in VarInt encoding: 1. Fixed `IndexOutOfRangeException` in `ProtoHelper.GetVarIntLength`. - Previously, `uint.CreateSaturating` converted negative values to 0, causing `BitOperations.LeadingZeroCount(0)` to return 32, which exceeded the `VarIntLengths32` array bounds. - Changed to `CreateTruncating` to preserve the bit pattern. 2. Fixed packet corruption in `ProtoWriter.EncodeVarInt`. - The check `if (value < 0x80)` was performing a signed comparison. Negative values (e.g., -1) were treated as single-byte values, breaking the Protobuf MSB rule and corrupting the stream. - Fixed by casting to `ulong` for unsigned comparison. Added regression tests to verify correctness for negative integer serialization.
This workflow automatically syncs the forked repository with the upstream repository on a daily schedule and allows manual triggering.
… when StartMessageSeq is null
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.
This PR addresses two critical issues identified during message serialization:
1. Fix VarInt Encoding for Negative Values ([Proto])
ProtoHelper.GetVarIntLengthuseduint.CreateSaturatingwhich converted negative values to 0, causingIndexOutOfRangeExceptioninVarIntLengths32.ProtoWriter.EncodeVarIntperformed a signed comparison (value < 0x80), causing negative integers (like -1) to be written as a single byte0xFF, corrupting the protobuf stream (e.g., breaking Base64 image uploads).CreateTruncatingand forcedulongcasting for unsigned comparison to preserve bit patterns.2. Fix Forward Message Image Upload ([Core])
MultiMsgEntity.Preprocessonly uploaded the outer container but failed to upload internal entities (like images). This resulted in emptyMsgInfoduring serialization and caused-400 Internal Server Error.Regression tests have been added to ensure stability.