From 12c0dab28fe71eaaa5ec8e5c61db59f4fc2d7187 Mon Sep 17 00:00:00 2001 From: stammw Date: Tue, 15 Jan 2019 08:07:29 +0100 Subject: [PATCH] QPACK: known the value of an invalid prefix, fix Literal prefix check --- quinn-h3/src/qpack/bloc.rs | 14 ++++++++------ quinn-h3/src/qpack/decoder.rs | 2 +- quinn-h3/src/qpack/mod.rs | 2 +- quinn-h3/src/qpack/stream.rs | 8 ++++---- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/quinn-h3/src/qpack/bloc.rs b/quinn-h3/src/qpack/bloc.rs index 6a670f28b..261c6a4c6 100644 --- a/quinn-h3/src/qpack/bloc.rs +++ b/quinn-h3/src/qpack/bloc.rs @@ -43,7 +43,7 @@ impl Indexed { match prefix_int::decode(6, buf)? { (0b11, i) => Ok(Indexed::Static(i)), (0b10, i) => Ok(Indexed::Dynamic(i)), - _ => Err(ParseError::InvalidPrefix), + (f, i) => Err(ParseError::InvalidPrefix(f)), } } @@ -62,7 +62,7 @@ impl IndexedWithPostBase { pub fn decode(buf: &mut R) -> Result { match prefix_int::decode(4, buf)? { (0b0001, i) => Ok(IndexedWithPostBase(i)), - _ => Err(ParseError::InvalidPrefix), + (f, _) => Err(ParseError::InvalidPrefix(f)), } } @@ -102,7 +102,7 @@ impl LiteralWithNameRef { i, prefix_string::decode(8, buf)?, )), - _ => Err(ParseError::InvalidPrefix), + (f, _) => Err(ParseError::InvalidPrefix(f)), } } @@ -141,7 +141,7 @@ impl LiteralWithPostBaseNameRef { i, prefix_string::decode(8, buf)?, )), - _ => Err(ParseError::InvalidPrefix), + (f, _) => Err(ParseError::InvalidPrefix(f)), } } @@ -167,8 +167,10 @@ impl Literal { } pub fn decode(buf: &mut R) -> Result { - if buf.remaining() > 0 && buf.bytes()[0] & 0b1110_0000 != 0b0010_0000 { - return Err(ParseError::InvalidPrefix); + if buf.remaining() < 1 { + return Err(ParseError::InvalidInteger(prefix_int::Error::UnexpectedEnd)); + } else if buf.bytes()[0] & 0b1110_0000 != 0b0010_0000 { + return Err(ParseError::InvalidPrefix(buf.bytes()[0])); } Ok(Literal::new( prefix_string::decode(4, buf)?, diff --git a/quinn-h3/src/qpack/decoder.rs b/quinn-h3/src/qpack/decoder.rs index 9086456dd..523feabb2 100644 --- a/quinn-h3/src/qpack/decoder.rs +++ b/quinn-h3/src/qpack/decoder.rs @@ -251,7 +251,7 @@ impl From for Error { match e { ParseError::InvalidInteger(x) => Error::InvalidInteger(x), ParseError::InvalidString(x) => Error::InvalidString(x), - ParseError::InvalidPrefix => Error::UnknownPrefix, + ParseError::InvalidPrefix(_) => Error::UnknownPrefix, } } } diff --git a/quinn-h3/src/qpack/mod.rs b/quinn-h3/src/qpack/mod.rs index 57698c90d..b57dae476 100644 --- a/quinn-h3/src/qpack/mod.rs +++ b/quinn-h3/src/qpack/mod.rs @@ -33,7 +33,7 @@ pub mod prefix_string; pub enum ParseError { InvalidInteger(prefix_int::Error), InvalidString(prefix_string::Error), - InvalidPrefix, + InvalidPrefix(u8), } impl From for ParseError { diff --git a/quinn-h3/src/qpack/stream.rs b/quinn-h3/src/qpack/stream.rs index 77d75f4e7..ec334a811 100644 --- a/quinn-h3/src/qpack/stream.rs +++ b/quinn-h3/src/qpack/stream.rs @@ -55,7 +55,7 @@ impl InsertWithNameRef { pub fn decode(buf: &mut R) -> Result, ParseError> { let (flags, index) = match prefix_int::decode(6, buf) { Ok((f, x)) if f & 0b10 == 0b10 => (f, x), - Ok((_, _)) => return Err(ParseError::InvalidPrefix), + Ok((f, _)) => return Err(ParseError::InvalidPrefix(f)), Err(IntError::UnexpectedEnd) => return Ok(None), Err(e) => return Err(e.into()), }; @@ -130,7 +130,7 @@ impl Duplicate { pub fn decode(buf: &mut R) -> Result, ParseError> { let index = match prefix_int::decode(5, buf) { Ok((0, x)) => x, - Ok((_, _)) => return Err(ParseError::InvalidPrefix), + Ok((f, _)) => return Err(ParseError::InvalidPrefix(f)), Err(IntError::UnexpectedEnd) => return Ok(None), Err(e) => return Err(e.into()), }; @@ -151,7 +151,7 @@ impl DynamicTableSizeUpdate { pub fn decode(buf: &mut R) -> Result, ParseError> { let size = match prefix_int::decode(5, buf) { Ok((0b001, x)) => x, - Ok((_, _)) => return Err(ParseError::InvalidPrefix), + Ok((f, _)) => return Err(ParseError::InvalidPrefix(f)), Err(IntError::UnexpectedEnd) => return Ok(None), Err(e) => return Err(e.into()), }; @@ -172,7 +172,7 @@ impl TableSizeSync { pub fn decode(buf: &mut R) -> Result, ParseError> { let insert_count = match prefix_int::decode(6, buf) { Ok((0b00, x)) => x, - Ok((_, _)) => return Err(ParseError::InvalidPrefix), + Ok((f, _)) => return Err(ParseError::InvalidPrefix(f)), Err(IntError::UnexpectedEnd) => return Ok(None), Err(e) => return Err(e.into()), };