codec: fix infinite loop in tokio_codec::LinesCodec (#1489)

This commit is contained in:
Newton Ni
2019-08-26 13:38:52 -07:00
committed by Carl Lerche
parent 654f9d703f
commit 807d536846
2 changed files with 43 additions and 28 deletions
+15
View File
@@ -188,6 +188,21 @@ fn lines_decoder_max_length_newline_between_decodes() {
assert_eq!("hello", codec.decode(buf).unwrap().unwrap());
}
// Regression test for [infinite loop bug](https://github.com/tokio-rs/tokio/issues/1483)
#[test]
fn lines_decoder_discard_repeat() {
const MAX_LENGTH: usize = 1;
let mut codec = LinesCodec::new_with_max_length(MAX_LENGTH);
let buf = &mut BytesMut::new();
buf.reserve(200);
buf.put("aa");
assert!(codec.decode(buf).is_err());
buf.put("a");
assert!(codec.decode(buf).is_err());
}
#[test]
fn lines_encoder() {
let mut codec = LinesCodec::new();