Skip to content

Commit d69d3c4

Browse files
committed
Fix overflow check
1 parent 4504f9c commit d69d3c4

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/message.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,10 @@ impl<W: Write> WriteMessage for W {
246246
}
247247

248248
// add size of length value
249-
try!(self.write_u32::<BigEndian>(try!(u32::from_usize(buf.len() + mem::size_of::<u32>()))));
249+
if buf.len() > u32::max_value() as usize - mem::size_of::<u32>() {
250+
return Err(io::Error::new(io::ErrorKind::InvalidInput, "value too large to transmit"));
251+
}
252+
try!(self.write_u32::<BigEndian>((buf.len() + mem::size_of::<u32>()) as u32));
250253
try!(self.write_all(&*buf));
251254

252255
Ok(())

0 commit comments

Comments
 (0)