From e4106c35462a782d6e3e4cc8c2f85a9fdf6fd32a Mon Sep 17 00:00:00 2001 From: kralverde Date: Fri, 6 Sep 2024 16:55:31 -0400 Subject: [PATCH] add buffer checks for varint decoding --- pumpkin-protocol/src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pumpkin-protocol/src/lib.rs b/pumpkin-protocol/src/lib.rs index dcc139b78..66caee7e9 100644 --- a/pumpkin-protocol/src/lib.rs +++ b/pumpkin-protocol/src/lib.rs @@ -44,6 +44,9 @@ impl VarInt { pub fn decode_partial(r: &mut &[u8]) -> Result { let mut val = 0; for i in 0..Self::MAX_SIZE { + if !r.has_remaining() { + return Err(VarIntDecodeError::Incomplete); + } let byte = r.get_u8(); val |= (i32::from(byte) & 0b01111111) << (i * 7); if byte & 0b10000000 == 0 { @@ -71,6 +74,9 @@ impl VarInt { pub fn decode(r: &mut &[u8]) -> Result { let mut val = 0; for i in 0..Self::MAX_SIZE { + if !r.has_remaining() { + return Err(VarIntDecodeError::Incomplete); + } let byte = r.get_u8(); val |= (i32::from(byte) & 0b01111111) << (i * 7); if byte & 0b10000000 == 0 {