Minetrack
Minetrack copied to clipboard
If the IP address is too short, an error message is displayed!
E:\MineTrack\node_modules\bytebuffer\dist\ByteBufferNB.js:633
throw RangeError("Illegal offset: 0 <= "+offset+" (+"+2+") <= "+this.buffer.length);
^
RangeError: Illegal offset: 0 <= 33 (+2) <= 33
at ByteBuffer.module.exports.ByteBufferPrototype.readInt16 (E:\MineTrack\node_modules\bytebuffer\dist\ByteBufferNB.js:633:23)
at UNCONNECTED_PONG.decode (E:\MineTrack\node_modules\mcpe-ping-fixed\index.js:68:29)
at E:\MineTrack\node_modules\mcpe-ping-fixed\index.js:140:14
at Socket.emit (node:events:390:28)
at UDP.onMessage [as onmessage] (node:dgram:939:8)
Node.js v17.2.0
{
"name": "test",
"ip": "106.2.xx.xx",
"type": "PE"
}
I've taken a look at the code, and I suspect the server is replying with corrupt data. The exception is thrown here:
// ...
UNCONNECTED_PONG.prototype.decode = function () {
this.pingId = this.bb.readLong();
this.serverId = this.bb.readLong();
this.bb.offset += 16;
this.nameLength = this.bb.readShort(); // <-- HERE
try {
this.advertiseString = this.bb.readUTF8String(this.nameLength);
}
catch(e){ //FIXME
this.advertiseString = this.bb.readUTF8String(parseInt(e.message.substr(e.message.indexOf(",")+2, 3)));
}
//...
};
The "Unconnected Pong" packet format is given in https://github.com/NiclasOlofsson/MiNET/blob/fc80766d69d27e02b04b57276e5744a5f17e3b28/src/MiNET/MiNET/Net/MCPE%20Protocol.xml#L45-L50. Note that we first read the ping ID, then the server ID, skip the 16-byte long OFFLINE_MESSAGE_DATA_ID
and then attempt to read the length of the Server Name
field. In this case, the buffer ends at this position, meaning there's no length to be read. wiki.vg specifies this field must be present even if the string is empty.
Unrelated, but the solution to the FIXME
below is to pass ByteBuffer.METRICS_BYTES
as the second argument to bb#readUTF8String
(it expects the number of characters by default), i.e. the updated method is
UNCONNECTED_PONG.prototype.decode = function () {
this.pingId = this.bb.readLong();
this.serverId = this.bb.readLong();
this.bb.offset += 16;
this.nameLength = this.bb.readShort();
this.advertiseString = this.bb.readUTF8String(this.nameLength, ByteBuffer.METRICS_BYTES);
var splitString = this.advertiseString.split(/;/g);
this.gameId = splitString[0];
this.name = splitString[1];
this.unknownId = splitString[2];
this.gameVersion = splitString[3];
this.currentPlayers = splitString[4];
this.maxPlayers = splitString[5];
};