PrismarineJS / bedrock-protocol

Minecraft Bedrock protocol library, with authentication and encryption
https://prismarinejs.github.io/minecraft-data/?v=bedrock_1.17.10&d=protocol
MIT License
308 stars 72 forks source link

(Relay) Error Parsing Packet on CubeCraft #436

Closed EthMC closed 1 year ago

EthMC commented 1 year ago

When using a relay on CubeCraft I get kicked while joining and I get this error in my console.

Capture

I've attached code as well as the packet read error below.

const { Relay } = require("bedrock-protocol");

const relay = new Relay({
  version: "1.20.0", // The version
  /* host and port to listen for clients on */
  host: "0.0.0.0",
  port: 19132,
  /* Where to send upstream packets to */
  destination: {
    host: "mco.cubecraft.net",
    port: 19132,
  },
});

console.log("proxy running!");

relay.listen(); // Tell the server to start listening.

1690075685189_packetReadError.txt

Majunti commented 1 year ago

Just set 35 here instead of 31 in prismarine-nbt/compiler-zigzag.js jstt

extremeheat commented 1 year ago

Can confirm with your buffer, seems like issue in packet_item_component decoding

extremeheat commented 1 year ago

OK, after looking into it, the issue seems to be NBT-related. One of the NBT tags' 32-bit varints is too big causing an integer overflow

{"type":"compound","name":"","value":{"name":{"type":"string","value":"cubecraft:dragon_bow"},"id":{"type":"int","value":25102},"components":{"type":"compound","value":{"item_properties":{"type":"compound","value":{"stacked_by_data":{"type":"byte","value":0},"hand_equipped":{"type":"byte","value":1},"frame_count":{"type":"int","value":3},"minecraft:icon":{"type":"compound","value":{"texture":{"type":"string","value":"cubecraft:dragon_bow"}}},"use_animation":{"type":"int","value":4},"animates_in_toolbar":{"type":"byte","value":1},"max_stack_size":{"type":"int","value":1},"use_duration":{"type":"int","value":["OVER",-2147483648]}}},"minecraft:shooter":{"type":"compound","value":{"charge_on_draw":{"type":"byte","value":0},"max_draw_duration":{"type":"float","value":1},"launch_power_scale":{"type":"float","value":1},"max_launch_power":{"type":"float","value":1}}},"minecraft:durability":{"type":"compound","value":{"max_durability":{"type":"int","value":384}}}}}}}

The server is not encoding the value correctly

extremeheat commented 1 year ago

I guess one fix would be to allow overflows up to the 64-bit limit, then throwing. The server is still wrong, and re-encoding will fail because of data-loss, but it may not be necessary to throw an exception there if the data can otherwise be read ok