Implement signed byte conversion for checksum to fix #3765#1442
Implement signed byte conversion for checksum to fix #3765#1442brentspine wants to merge 2 commits intoPrismarineJS:masterfrom
Conversation
|
@copilot Review ? (idk if it works like that) |
There was a problem hiding this comment.
Pull request overview
This PR implements signed byte conversion for chat checksums to fix issue #3765. The Minecraft 1.21.5+ protocol expects checksums to be signed bytes (range -128 to 127) rather than unsigned bytes (range 0-255), which was causing protocol validation issues.
- Adds a
toSignedByteutility function to convert unsigned bytes to signed bytes - Applies the conversion to the checksum field in chat command packets for version 1.21.5+
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const toSignedByte = (value) => { | ||
| const byte = value & 0xff | ||
| return byte > 127 ? byte - 256 : byte | ||
| } |
There was a problem hiding this comment.
Consider moving the toSignedByte function to src/datatypes/checksums.js and exporting it alongside computeChatChecksum. This would improve code organization by grouping related checksum functionality together and make the function reusable if needed elsewhere. The function is specifically designed to handle the signed byte requirement for checksums in the Minecraft protocol.
There was a problem hiding this comment.
@copilot coauthor pr #1442 based on this this feedback
|
Thanks |
| argumentSignatures: canSign ? signaturesForCommand(command, options.timestamp, options.salt, options.preview, acknowledgements) : [], | ||
| messageCount: client._lastSeenMessages.pending, | ||
| checksum: computeChatChecksum(client._lastSeenMessages), // 1.21.5+ | ||
| checksum: toSignedByte(computeChatChecksum(client._lastSeenMessages)), // 1.21.5+ |
There was a problem hiding this comment.
This branch specifically covers the chat commands only. Is this intentional? Your linked issue PrismarineJS/mineflayer#3765 seems to hint at normal chat messages too
There was a problem hiding this comment.
I only encountered this with commands. Would you mind using my fix yourself? It's easier than me doing it
|
It's also already clamped here https://github.com/PrismarineJS/node-minecraft-protocol/blob/master/src/datatypes/checksums.js#L16 |
|
Great find on the checksum issue! We're experiencing a related but distinct overflow problem that might benefit from the same The
|
Fixes ERR_OUT_OF_RANGE crash when pending acknowledgment counter exceeds 127. The messageCount, offset, and checksum fields in chat packets are serialized as signed bytes (i8, range -128 to 127). The pending counter can exceed this range on busy servers before the bot sends its first message. This patch applies toSignedByte() conversion to: - messageCount in chat_command/chat_command_signed packets - offset in chat_message packets - checksum in both (for 1.21.5+) Fixes: PrismarineJS/mineflayer#3765 Related: PrismarineJS#1442
Fix PrismarineJS/mineflayer#3765