Skip to content

utf8: point the non-UTF-8 guard at the offending byte - #4246

Merged
bylins merged 1 commit into
masterfrom
fix/utf8-guard-points-at-the-bad-byte
Nov 23, 2026
Merged

bylins merged 1 commit into
masterfrom
fix/utf8-guard-points-at-the-bad-byte

Conversation

@bylins

@bylins bylins commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Что видно в логе

Предохранитель в string_to_client_encoding (из #3681) срабатывает на боевом с 17.11 — примерно по десятку строк за запуск сервера, и это нижняя оценка: счётчик печатает первые десять и дальше каждую десятитысячную, так что настоящий поток неизвестен. Полезной ни одна строка не оказалась:

SYSERR: клиенту уходит не-UTF-8 (#1) -- где-то пропущена граница чтения.
Первые байты: 0d 0a 4f 6e 6c 69 6e 65 3a 20 31 30 32 0d 0a 0d

Это "\r\nOnline: 102\r\n\r" — приветствие при подключении и начало приглашения выбрать кодировку, чистая латиница. Начало у битой строки целое, испорченный байт лежит дальше, и дамп до него не доходил.

Три разные подписи за неделю, то есть причина не одна:

байты что это
0d 0a 4f 6e 6c 69 6e 65 3a ... свежее подключение, большинство случаев
0d 0a e5 f2 20 e7 e4 e5 f1 fc 2e «ет здесь.» в CP1251 — текст пришёл сюда уже перекодированным
0d 0a 33 30 6d 20 2d 20 30m - , хвост ANSI-последовательности

Вторая подпись — самая интересная: на вход предохранителю должен приходить нативный UTF-8, а приходит уже готовый CP1251. Но по шестнадцати байтам от начала дальше не продвинуться.

Правка

Добавлен utf8::find_invalid — смещение первого ill-formed байта (is_valid теперь строка над ним) — и строка перестроена вокруг этого смещения:

SYSERR: клиенту уходит не-UTF-8 (#1) -- где-то пропущена граница чтения.
Байт 412 из 418, состояние 'Playing', кодировка 2,
байты вокруг: 20 d0 bf d1 80 d0 be d1 87 d0 be *d0

Номер байта, длина буфера, байты с двух сторон (испорченный помечен звёздочкой), состояние дескриптора и кодировка. Без последних двух нельзя отличить вывод до входа в игру от вывода играющему — а подписи говорят, что это разные случаи.

На то, что уходит клиенту, правка не влияет: меняется только диагностика. Починки тут нет намеренно — сначала строка, которая скажет, куда смотреть.

Проверка

build_nounity (-Dunity=off), 933 теста, 930 прошли, 3 отключены штатно. Добавлен Utf8.FindInvalidPointsAtTheOffendingByte: смещение на чистой строке, на одиночном байте, на обрезанном хвосте (случай с боевого) и на первой из двух поломок.

🤖 Generated with Claude Code

The guard in string_to_client_encoding has fired about ten times per
server run since 17.11 -- the counter caps at ten, so the real rate is
unknown -- and not one line has been usable. It printed sixteen bytes
from the head of the buffer, and the head of a broken string is intact:

    Первые байты: 0d 0a 4f 6e 6c 69 6e 65 3a 20 31 30 32 0d 0a 0d

That is "\r\nOnline: 102\r\n\r", the login banner plus the start of the
codepage prompt, both pure ASCII. The bad byte is somewhere further on
and the dump never reached it.

Added utf8::find_invalid, which returns the offset of the first
ill-formed byte (is_valid is now one line over it), and rebuilt the
diagnostic around that offset: the byte number, the buffer length, the
bytes on both sides with the offender starred, and the descriptor's
state and codepage -- without the last two there is no telling output
before login from output to a player in the game.

Nothing about what is sent to the client changes; this is the diagnostic
only. The three byte signatures seen on the live server (a fresh
connection, text already converted to CP1251, and the tail of an ANSI
sequence) suggest more than one cause, which is why the next step is a
line that says where to look rather than a guess at a fix.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@bylins
bylins merged commit 8be41f6 into master Nov 23, 2026
20 checks passed
@bylins
bylins deleted the fix/utf8-guard-points-at-the-bad-byte branch November 23, 2026 16:45
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