Fix overflow check
This commit is contained in:
parent
4504f9cec8
commit
d69d3c4aad
@ -246,7 +246,10 @@ impl<W: Write> WriteMessage for W {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add size of length value
|
// add size of length value
|
||||||
try!(self.write_u32::<BigEndian>(try!(u32::from_usize(buf.len() + mem::size_of::<u32>()))));
|
if buf.len() > u32::max_value() as usize - mem::size_of::<u32>() {
|
||||||
|
return Err(io::Error::new(io::ErrorKind::InvalidInput, "value too large to transmit"));
|
||||||
|
}
|
||||||
|
try!(self.write_u32::<BigEndian>((buf.len() + mem::size_of::<u32>()) as u32));
|
||||||
try!(self.write_all(&*buf));
|
try!(self.write_all(&*buf));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
Reference in New Issue
Block a user