frame: fix integer overflow

This is a security fix.
Fixes #33.

Signed-off-by: Alexey Galakhov <agalakhov@snapview.de>
pull/37/head
Alexey Galakhov 6 years ago
parent b93abcf900
commit c0cde68999
  1. 14
      src/protocol/frame/frame.rs

@ -344,7 +344,7 @@ impl Frame {
None None
}; };
if size < length + header_length { if size < header_length || size - header_length < length {
cursor.set_position(initial); cursor.set_position(initial);
return Ok(None) return Ok(None)
} }
@ -511,6 +511,16 @@ mod tests {
fn display() { fn display() {
let f = Frame::message("hi there".into(), OpCode::Data(Data::Text), true); let f = Frame::message("hi there".into(), OpCode::Data(Data::Text), true);
let view = format!("{}", f); let view = format!("{}", f);
view.contains("payload:"); assert!(view.contains("payload:"));
}
#[test]
fn parse_overflow() {
let mut raw: Cursor<Vec<u8>> = Cursor::new(vec![
0x83, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
]);
let frame_none = Frame::parse(&mut raw).unwrap();
assert!(frame_none.is_none());
} }
} }

Loading…
Cancel
Save