Skip to content

Fix computeChatChecksum returning unsigned byte for i8 schema (closes #1482)#1485

Merged
extremeheat merged 1 commit intoPrismarineJS:masterfrom
mio-rei:fix/checksum-signed-byte
May 4, 2026
Merged

Fix computeChatChecksum returning unsigned byte for i8 schema (closes #1482)#1485
extremeheat merged 1 commit intoPrismarineJS:masterfrom
mio-rei:fix/checksum-signed-byte

Conversation

@mio-rei
Copy link
Copy Markdown
Contributor

@mio-rei mio-rei commented May 2, 2026

Summary

The chat_command_signed packet schema defines the checksum as i8 (-128..127), but computeChatChecksum was returning the result of & 0xff (0..255). When the masked checksum exceeded 127, the protocol writer rejected it with RangeError: The value of \"value\" is out of range. It must be >= -128 and <= 127. Received N, breaking any signed slash command on MC 1.21.11.

Closes #1482.

Fix

Convert the unsigned byte to signed range before returning:

const unsigned = checksum & 0xff
const signed = unsigned > 127 ? unsigned - 256 : unsigned
return signed === 0 ? 1 : signed

Test plan

  • Locally patched node_modules/minecraft-protocol/src/datatypes/checksums.js with the same conversion against MC 1.21.11 vanilla server (LAN), bot has been sending /say / /tell for ~14 days without RangeError.
  • Adding a unit test to the repo would be nice — happy to follow up if reviewers want one in this PR.

Notes

Issue #1482 has the full repro steps (versions, error, root cause). This PR is the minimal fix; the value-zero guard (return 1) is preserved.

The chat_command_signed packet schema defines the checksum as i8 (-128..127),
but computeChatChecksum was returning the result of '& 0xff' (0..255). When
the masked value exceeded 127, sending any signed chat command crashed with
RangeError on MC 1.21.11.

Convert the unsigned byte to signed range before returning. Closes PrismarineJS#1482.
@extremeheat extremeheat merged commit a263bb9 into PrismarineJS:master May 4, 2026
33 checks passed
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.

computeChatChecksum returns unsigned byte but schema is i8 → RangeError on MC 1.21.11

2 participants