node-minecraft-protocol icon indicating copy to clipboard operation
node-minecraft-protocol copied to clipboard

Don't throw errors in framing Splitter class if hideErrors is enabled

Open matthi4s opened this issue 3 years ago • 3 comments

Currently, the server occasionally crashes with an error thrown in the Splitter class in the framing.js module:

.../node_modules/minecraft-protocol/src/transforms/framing.js:67
          } else { throw e }
                   ^
RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 377. Received -939024210
    at new NodeError (node:internal/errors:371:5)
    at boundsError (node:internal/buffer:86:9)
    at Buffer.readUInt8 (node:internal/buffer:252:5)
    at readVarInt (/aternos/nodejs/hypnos/node_modules/protodef/src/datatypes/utils.js:70:22)
    at Splitter._transform (/aternos/nodejs/hypnos/node_modules/minecraft-protocol/src/transforms/framing.js:63:30)
    at Splitter.Transform._read (/aternos/nodejs/hypnos/node_modules/readable-stream/lib/_stream_transform.js:177:10)
    at Splitter.Transform._write (/aternos/nodejs/hypnos/node_modules/readable-stream/lib/_stream_transform.js:164:83)
    at doWrite (/aternos/nodejs/hypnos/node_modules/readable-stream/lib/_stream_writable.js:409:139)
    at writeOrBuffer (/aternos/nodejs/hypnos/node_modules/readable-stream/lib/_stream_writable.js:398:5)
    at Splitter.Writable.write (/aternos/nodejs/hypnos/node_modules/readable-stream/lib/_stream_writable.js:307:11) {
  code: 'ERR_OUT_OF_RANGE'
}

This shouldn't happen when the hideErrors option is enabled. I've passed the hideErrors option from the Client to the Splitter and it now only throws the errors when hideErrors is disabled.

matthi4s avatar Apr 12 '22 15:04 matthi4s

I don't think that's a good change This is not a recoverable error It should crash

rom1504 avatar Apr 13 '22 11:04 rom1504

I'm not sure what exactly is causing this error, but I guess that it's caused by invalid data received from the client? It shouldn't be possible to crash the server through anything sent by the client.

matthi4s avatar Apr 13 '22 11:04 matthi4s

Yeah that makes sense. So the correct thing to do should be closing that client connection.

rom1504 avatar Apr 13 '22 12:04 rom1504