From 6e61fc9b0b1057b943761b1b48107c2f3b0ea16a Mon Sep 17 00:00:00 2001 From: Marek Kuskowski <50183564+nylonicious@users.noreply.github.com> Date: Wed, 8 Jan 2025 07:33:52 +0100 Subject: [PATCH] use assert! to verify length number --- src/protocol/frame/frame.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/protocol/frame/frame.rs b/src/protocol/frame/frame.rs index 5df8734..baede5b 100644 --- a/src/protocol/frame/frame.rs +++ b/src/protocol/frame/frame.rs @@ -161,13 +161,9 @@ impl FrameHeader { let length_length = LengthFormat::for_byte(length_byte).extra_bytes(); if length_length > 0 { const SIZE: usize = mem::size_of::(); + assert!(length_length <= SIZE, "length exceeded size of u64"); + let start = SIZE - length_length; let mut buffer = [0; SIZE]; - let start = match SIZE.checked_sub(length_length) { - Some(start) => start, - None => { - panic!("the integer can fit {} bytes, but {} is given", SIZE, length_length) - } - }; match cursor.read_exact(&mut buffer[start..]) { Err(ref err) if err.kind() == ErrorKind::UnexpectedEof => return Ok(None), Err(err) => return Err(err.into()),