Skip to content

Commit 2119b04

Browse files
PiotrW01extremeheatCopilot
authored
Fix undefined chat message signatures causing crash (#1413)
* Fix undefined chat message signatures causing crash * Update src/client/chat.js Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update chat.js lint --------- Co-authored-by: extremeheat <extreme@protonmail.ch> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 5242498 commit 2119b04

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/client/chat.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,14 @@ module.exports = function (client, options) {
5959

6060
if (player.hasChainIntegrity) {
6161
const length = Buffer.byteLength(message, 'utf8')
62-
const acknowledgements = previousMessages.length > 0 ? ['i32', previousMessages.length, 'buffer', Buffer.concat(...previousMessages.map(msg => msg.signature || client._signatureCache[msg.id]))] : ['i32', 0]
63-
62+
const validBuffers = previousMessages
63+
.filter(msg => msg.signature || client._signatureCache[msg.id]) // Filter out invalid messages
64+
.map(msg => msg.signature || client._signatureCache[msg.id])
65+
.filter(buf => Buffer.isBuffer(buf))
66+
67+
const acknowledgements = validBuffers.length > 0
68+
? ['i32', validBuffers.length, 'buffer', Buffer.concat(validBuffers)]
69+
: ['i32', 0]
6470
const signable = concat('i32', 1, 'UUID', uuid, 'UUID', player.sessionUuid, 'i32', index, 'i64', salt, 'i64', timestamp / 1000n, 'i32', length, 'pstring', message, ...acknowledgements)
6571

6672
player.hasChainIntegrity = crypto.verify('RSA-SHA256', signable, player.publicKey, currentSignature)

0 commit comments

Comments
 (0)