Strip invalid UTF-8 char from end of player names.#545
Merged
Conversation
| size_t newPos = i + cCharBytes; | ||
| if (newPos > (sizeof(szNewName) - 1)) | ||
| { | ||
| szNewName[i] = 0; |
Member
There was a problem hiding this comment.
You should do this after the loop regardless, because if you break normally this will not be written to the array.
Member
Author
There was a problem hiding this comment.
The array is already NULL terminated. This is just for adding it sooner.
Member
There was a problem hiding this comment.
Right; sorry. lgtm
I kind of wonder about targeting though. If you copy the entire string we won't find the name anymore because the names would vary between the engine and SM. This is if the last, invalid character is actually sent to the client.
Member
Author
There was a problem hiding this comment.
The last character wouldn't be printable, so it shouldn't exist in display anywhere to copy from.
psychonic
added a commit
that referenced
this pull request
Oct 7, 2016
asherkin
added a commit
that referenced
this pull request
Jul 18, 2021
In #545 we started automatically fixing up invalid UTF8 characters caused by truncated names from Steam, but since the dawn of time CPlayer has preferred directly returning the engine's name pointer if we have once available, so our corrected name is almost never used. Lightly tested in CS:GO and TF2 with no ill effects. Fixes #1315
asherkin
added a commit
that referenced
this pull request
Aug 2, 2021
In #545 we started automatically fixing up invalid UTF8 characters caused by truncated names from Steam, but since the dawn of time CPlayer has preferred directly returning the engine's name pointer if we have once available, so our corrected name is almost never used. Lightly tested in CS:GO and TF2 with no ill effects. Fixes #1315
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.
Steam supports player names up to 32 UTF-8 characters, excluding the NULL terminator. The Source Engine supports either 32 or 128 bytes for a name (depending on version), including the NULL terminator.
In all cases, this can lead to the engine copy of the name ending in the middle of a character due to the truncation. When this occurs, rather than passing this copy of the name to the GetClientName native and the %N format specifier, let's fix our stored copy.