Skip to content

Commit

Permalink
minecraft: Split vanilla string by bytes instead of characters (#436)
Browse files Browse the repository at this point in the history
The received string length from server is expected to be a byte length
whereas if we parse to string first javascript will treat our length as
a character length (accounts for UTF multi-byte characters).

This should hopefully fix #434
  • Loading branch information
Douile authored Dec 17, 2023
1 parent ec33bc2 commit dcc69a3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions protocols/minecraftvanilla.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export default class minecraftvanilla extends Core {
const strLen = reader.varint()
this.logger.debug('String Length: ' + strLen)

const str = reader.rest().toString('utf8')
const rest = reader.rest()

const str = rest.toString('utf8', 0, strLen)
this.logger.debug(str)

const json = JSON.parse(str.substring(0, strLen))
Expand All @@ -61,8 +63,8 @@ export default class minecraftvanilla extends Core {
// Better Compatibility Checker mod support
let bccJson = {}

if (str.length > strLen) {
const bccStr = str.substring(strLen + 1)
if (rest.length > strLen) {
const bccStr = rest.toString('utf8', strLen + 1)
bccJson = JSON.parse(bccStr)
}

Expand Down

0 comments on commit dcc69a3

Please sign in to comment.