mirror of
https://github.com/n0-computer/noq.git
synced 2026-09-24 20:25:00 +00:00
QPACK: known the value of an invalid prefix, fix Literal prefix check
This commit is contained in:
@@ -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<R: Buf>(buf: &mut R) -> Result<Self, ParseError> {
|
||||
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<R: Buf>(buf: &mut R) -> Result<Self, ParseError> {
|
||||
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)?,
|
||||
|
||||
@@ -251,7 +251,7 @@ impl From<ParseError> for Error {
|
||||
match e {
|
||||
ParseError::InvalidInteger(x) => Error::InvalidInteger(x),
|
||||
ParseError::InvalidString(x) => Error::InvalidString(x),
|
||||
ParseError::InvalidPrefix => Error::UnknownPrefix,
|
||||
ParseError::InvalidPrefix(_) => Error::UnknownPrefix,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ pub mod prefix_string;
|
||||
pub enum ParseError {
|
||||
InvalidInteger(prefix_int::Error),
|
||||
InvalidString(prefix_string::Error),
|
||||
InvalidPrefix,
|
||||
InvalidPrefix(u8),
|
||||
}
|
||||
|
||||
impl From<prefix_int::Error> for ParseError {
|
||||
|
||||
@@ -55,7 +55,7 @@ impl InsertWithNameRef {
|
||||
pub fn decode<R: Buf>(buf: &mut R) -> Result<Option<Self>, 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<R: Buf>(buf: &mut R) -> Result<Option<Self>, 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<R: Buf>(buf: &mut R) -> Result<Option<Self>, 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<R: Buf>(buf: &mut R) -> Result<Option<Self>, 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()),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user