diff --git a/src/packet.rs b/src/packet.rs index 7b083f0..549a301 100644 --- a/src/packet.rs +++ b/src/packet.rs @@ -58,6 +58,9 @@ pub enum Packet { impl Packet { /// Deserializes a [`u8`] slice into a [`Packet`]. pub fn deserialize(buf: &[u8]) -> Result> { + if buf.len() < 2 { + return Err("Buffer too short to serialize".into()); + } let opcode = Opcode::from_u16(Convert::to_u16(&buf[0..=1])?)?; match opcode {