Skip to content

Commit

Permalink
suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
ogabrielides committed Nov 1, 2024
1 parent 6b76485 commit fb58431
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions dash/src/consensus/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -912,12 +912,26 @@ pub fn read_compact_size<R: Read + ?Sized>(r: &mut R) -> io::Result<u32> {
0xFD => {
let mut buf = [0u8; 2];
r.read_exact(&mut buf)?;
Ok(u16::from_le_bytes(buf) as u32)
let value = u16::from_le_bytes(buf) as u32;
if value < 0xFD {
return Err(io::Error::new(
io::ErrorKind::InvalidData,
"Non-minimal compact size encoding",
));
}
Ok(value)
}
0xFE => {
let mut buf = [0u8; 4];
r.read_exact(&mut buf)?;
Ok(u32::from_le_bytes(buf))
let value = u32::from_le_bytes(buf);
if value <= 0xFFFF {
return Err(io::Error::new(
io::ErrorKind::InvalidData,
"Non-minimal compact size encoding",
));
}
Ok(value)
}
0xFF => {
// Value is too large to fit in u32
Expand Down

0 comments on commit fb58431

Please sign in to comment.