Skip to content

Commit a263bb9

Browse files
authored
Fix computeChatChecksum returning unsigned byte for i8 schema (#1485)
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 #1482.
1 parent 3fabf16 commit a263bb9

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/datatypes/checksums.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ function computeChatChecksum (lastSeenMessages) {
1212
checksum = (31 * checksum + sigHash) & 0xffffffff
1313
}
1414
}
15-
// Convert to byte
16-
const result = checksum & 0xff
17-
return result === 0 ? 1 : result
15+
// Convert to signed byte (i8: -128..127) to match the chat_command_signed packet schema.
16+
// The previous `& 0xff` produced 0..255 which causes RangeError when value > 127.
17+
const unsigned = checksum & 0xff
18+
const signed = unsigned > 127 ? unsigned - 256 : unsigned
19+
return signed === 0 ? 1 : signed
1820
}
1921

2022
module.exports = { computeChatChecksum }

0 commit comments

Comments
 (0)