aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/read.rs
diff options
context:
space:
mode:
authorUbuntu <github@matdoes.dev>2022-08-31 18:48:51 +0000
committerUbuntu <github@matdoes.dev>2022-08-31 18:48:51 +0000
commitefb1f3f2d59af4dc44304d1f23678ac667c5cae2 (patch)
treed5f62931dbd97c99f3e39d6788e2b40742168503 /azalea-protocol/src/read.rs
parent0085f8a565563ecb6a9f4f87be8b336157aa1e55 (diff)
downloadazalea-drasl-efb1f3f2d59af4dc44304d1f23678ac667c5cae2.tar.xz
fix panics
Diffstat (limited to 'azalea-protocol/src/read.rs')
-rwxr-xr-xazalea-protocol/src/read.rs13
1 files changed, 12 insertions, 1 deletions
diff --git a/azalea-protocol/src/read.rs b/azalea-protocol/src/read.rs
index 077e1297..85340f5a 100755
--- a/azalea-protocol/src/read.rs
+++ b/azalea-protocol/src/read.rs
@@ -50,6 +50,8 @@ pub enum FrameSplitterError {
#[from]
source: std::io::Error,
},
+ #[error("Packet is longer than {max} bytes (is {size})")]
+ BadLength { max: u32, size: u32 },
}
async fn frame_splitter<R: ?Sized>(mut stream: &mut R) -> Result<Vec<u8>, FrameSplitterError>
@@ -57,7 +59,16 @@ where
R: AsyncRead + std::marker::Unpin + std::marker::Send,
{
// Packet Length
- let length = read_varint_async(&mut stream).await?;
+ let length = read_varint_async(&mut stream).await? as u32;
+
+ let max_length: u32 = 2u32.pow(20u32); // 1mb, arbitrary
+ if length > max_length {
+ // minecraft *probably* won't send packets bigger than this
+ return Err(FrameSplitterError::BadLength {
+ max: max_length,
+ size: length,
+ });
+ }
let mut buf = vec![0; length as usize];
stream.read_exact(&mut buf).await?;