diff --git a/src/types/packet.rs b/src/types/packet.rs index 465340f..09ceb1a 100644 --- a/src/types/packet.rs +++ b/src/types/packet.rs @@ -1,4 +1,4 @@ -use core::convert::TryInto; +use core::convert::{TryFrom, TryInto}; use crate::constants::*; @@ -119,7 +119,11 @@ impl From> for RawPacket { let len = block.data.len(); packet.resize_default(10 + len).ok(); packet[0] = 0x80; - packet[1..][..4].copy_from_slice(&len.to_le_bytes()); + packet[1..][..4].copy_from_slice( + &u32::try_from(len) + .expect("Packets should not be more than 4GiB") + .to_le_bytes(), + ); packet[5] = 0; packet[6] = block.seq;