Snowiiii / Pumpkin

Empowering everyone to host fast and efficient Minecraft servers.
https://snowiiii.github.io/Pumpkin/
MIT License
2.64k stars 78 forks source link

Incoming Packet Validation #78

Closed kralverde closed 1 month ago

kralverde commented 1 month ago

Got this error after leaving the server on a public ip:

thread 'main' panicked at /home/minecraft/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bytes-1.7.1/src/bytes_mut.rs:394:9:
split_to out of bounds: 3 <= 2
stack backtrace:
   0: rust_begin_unwind
             at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/panicking.rs:652:5
   1: core::panicking::panic_fmt
             at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/core/src/panicking.rs:72:14
   2: bytes::bytes_mut::BytesMut::split_to
             at /home/minecraft/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bytes-1.7.1/src/bytes_mut.rs:394:9
   3: <bytes::bytes_mut::BytesMut as bytes::buf::buf_impl::Buf>::copy_to_bytes
             at /home/minecraft/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bytes-1.7.1/src/bytes_mut.rs:1165:9
   4: pumpkin_protocol::bytebuf::ByteBuffer::get_string_len
             at ./pumpkin-protocol/src/bytebuf/mod.rs:87:20
   5: <pumpkin_protocol::server::handshake::SHandShake as pumpkin_protocol::ServerPacket>::read
             at ./pumpkin-protocol/src/server/handshake/mod.rs:20:29
   6: pumpkin::client::Client::handle_packet::{{closure}}
             at ./pumpkin/src/client/mod.rs:172:51
   7: pumpkin::client::Client::process_packets::{{closure}}
             at ./pumpkin/src/client/mod.rs:150:59
   8: pumpkin::main::{{closure}}
             at ./pumpkin/src/main.rs:186:69
   9: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/core/src/future/future.rs:123:9
  10: tokio::runtime::park::CachedParkThread::block_on::{{closure}}
             at /home/minecraft/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.39.2/src/runtime/park.rs:281:63
  11: tokio::runtime::coop::with_budget
             at /home/minecraft/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.39.2/src/runtime/coop.rs:107:5
  12: tokio::runtime::coop::budget
             at /home/minecraft/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.39.2/src/runtime/coop.rs:73:5
  13: tokio::runtime::park::CachedParkThread::block_on
             at /home/minecraft/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.39.2/src/runtime/park.rs:281:31
  14: tokio::runtime::context::blocking::BlockingRegionGuard::block_on
             at /home/minecraft/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.39.2/src/runtime/context/blocking.rs:66:9
  15: tokio::runtime::scheduler::multi_thread::MultiThread::block_on::{{closure}}
             at /home/minecraft/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.39.2/src/runtime/scheduler/multi_thread/mod.rs:87:13
  16: tokio::runtime::context::runtime::enter_runtime
             at /home/minecraft/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.39.2/src/runtime/context/runtime.rs:65:16
  17: tokio::runtime::scheduler::multi_thread::MultiThread::block_on
             at /home/minecraft/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.39.2/src/runtime/scheduler/multi_thread/mod.rs:86:9
  18: tokio::runtime::runtime::Runtime::block_on_inner
             at /home/minecraft/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.39.2/src/runtime/runtime.rs:363:45
  19: tokio::runtime::runtime::Runtime::block_on
             at /home/minecraft/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.39.2/src/runtime/runtime.rs:333:13
  20: pumpkin::main
             at ./pumpkin/src/main.rs:58:5
  21: core::ops::function::FnOnce::call_once
             at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

This PR hopes to prevent these panics in the case of bad packets, instead propagating errors up

Snowiiii commented 1 month ago

Hey, Great Job this was on my todo list aswell. I wonder since when this error is there?. I never encountered it myself. Is this only with Public IP or also with normal

kralverde commented 1 month ago

This was public, someone sending bad packets

Snowiiii commented 1 month ago

This was public, someone sending bad packets

Ah. You mean just random bad packets?. Okay i get it. I tought there would be an error when doing normal client behavoiur

Snowiiii commented 1 month ago

Thanks you @kralverde