Skip to content

Strip invalid UTF-8 char from end of player names.#545

Merged
psychonic merged 1 commit intomasterfrom
invalid-utf8-name
Oct 2, 2016
Merged

Strip invalid UTF-8 char from end of player names.#545
psychonic merged 1 commit intomasterfrom
invalid-utf8-name

Conversation

@psychonic
Copy link
Member

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.

size_t newPos = i + cCharBytes;
if (newPos > (sizeof(szNewName) - 1))
{
szNewName[i] = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should do this after the loop regardless, because if you break normally this will not be written to the array.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The array is already NULL terminated. This is just for adding it sooner.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last character wouldn't be printable, so it shouldn't exist in display anywhere to copy from.

@psychonic psychonic merged commit 999f378 into master Oct 2, 2016
@psychonic psychonic deleted the invalid-utf8-name branch October 2, 2016 22:34
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
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.

2 participants