Fix buffer overflow in Sink for Vec<u8>

Fixes #46
This commit is contained in:
Stefan Bühler
2016-09-03 13:25:40 -07:00
committed by Carl Lerche
parent d0d27bd540
commit f693e038d9
2 changed files with 16 additions and 2 deletions
+13
View File
@@ -1,6 +1,7 @@
use bytes::{Buf};
use byteorder;
use std::io::{Cursor};
use std::vec::{Vec};
#[test]
pub fn test_fresh_cursor_vec() {
@@ -44,3 +45,15 @@ fn test_read_u16_buffer_underflow() {
let mut buf = Cursor::new(b"\x21");
buf.read_u16::<byteorder::BigEndian>();
}
#[test]
fn test_vec_sink_capacity() {
use bytes::Sink;
let mut sink: Vec<u8> = Vec::new();
sink.reserve(16);
assert!(sink.capacity() >= 16, "Capacity {} must be at least 16", sink.capacity());
let mut source = Cursor::new(b"0123456789abcdef0123456789abcdef");
sink.copy_from(&mut source);
assert!(sink.len() <= sink.capacity(), "Length {} must be less than or equal to capacity {}", sink.len(), sink.capacity());
}