fix(libsidecar): write one group member GUID per slot - #84
Open
3kynox wants to merge 1 commit into
Open
Conversation
The destination pointer was reassigned on every iteration and then advanced by i elements, so the writes landed at 0, 1, 3, 6, 10... instead of 0, 1, 2, 3, 4. A group of three or more members shipped an uninitialized slot to the world server, and the last writes went past the end of the allocated array. Reported by sudlud while cross-checking ToCloud9 against the clustering PR. Index the array instead of walking a pointer, and cover it with a test that poisons guard slots to catch a write past the end.
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.
Reported by @sudlud while cross-checking this repository against the AzerothCore clustering PR:
OnGroupCreateddelivers garbage member GUIDs for groups of three or more, and the world server then materializes phantom members out of character cache misses.The cause is in
GroupCreated: the destination pointer is reassigned on every iteration and then advanced byielements, so it walks a cumulative sum instead of a fixed stride.Two consequences, the second one worth flagging beyond the original report:
mallocreturned;Parties of two are unaffected, which is probably why it went unnoticed.
The rest of the file already indexes from the base pointer (
battleground-api.go,petition-api.go,events-guilds.go) or advances by exactly one element (lib.go), so this is an isolated slip rather than a convention.Fix
The write loop moves into a small
writeMemberGUIDshelper that takes anunsafe.Sliceover the allocated block and indexes it, which makes an out of range write impossible by construction and lets the logic be tested.Test
TestWriteMemberGUIDsfills groups of 1, 2, 3 and 5 members into a buffer whose trailing guard slots are poisoned, then checks that every member landed in its own slot and that no guard was touched. Against the previous implementation it fails on the three member case (slot 2 holds 57005, expected 102), and it passes with this change.The native C++ sidecar is not affected — it passes
std::vector::data()— so only deployments running the Go sidecar see the bug.