Skip to content

Preserve non-ASCII bytes when computing checksums and writing messages - #20

Merged
GaryHughes merged 1 commit into
GaryHughes:masterfrom
sgolev:fix-encoding
Sep 24, 2026
Merged

GaryHughes merged 1 commit into
GaryHughes:masterfrom
sgolev:fix-encoding

Conversation

@sgolev

@sgolev sgolev commented Sep 21, 2026

Copy link
Copy Markdown

Problem

The checksum is computed incorrectly for any message containing non-ASCII bytes. Those messages fail validation, causing the session to desynchronize and eventually die.
A similar encoding issue exists for the message writer: non-ASCII data is lost.

Cause

The checksum should be the sum of the bytes on the wire, but Field.ComputeCheckSum() re-encoded the value with Encoding.ASCII. That encoder is lossy: every byte above 0x7F is replaced with '?' (0x3F). Any message carrying non-ASCII data therefore fails validation.

Fix

Use Encoding.Latin1 instead of Encoding.ASCII. The former maps 0x00-0xFF range one-to-one and is the exact inverse to (char)result. It is identical to ASCII for 0x00-0x7F range, therefore nothing changes for ASCII-only sessions.

@GaryHughes
GaryHughes self-requested a review September 22, 2026 11:35
@GaryHughes GaryHughes self-assigned this Sep 22, 2026
@GaryHughes

Copy link
Copy Markdown
Owner

Thanks for the fix @sgolev, there are a couple things that still need addressing but I'll merge and then make those changes.

@GaryHughes
GaryHughes merged commit b8cc594 into GaryHughes:master Sep 24, 2026
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