diff --git a/quinn-proto/src/packet.rs b/quinn-proto/src/packet.rs index 81486e14d..6ab361f2c 100644 --- a/quinn-proto/src/packet.rs +++ b/quinn-proto/src/packet.rs @@ -536,6 +536,9 @@ impl PlainHeader { grease_quic_bit: bool, ) -> Result { let first = buf.get::()?; + if !grease_quic_bit && first & FIXED_BIT == 0 { + return Err(PacketDecodeError::InvalidHeader("fixed bit unset")); + } if first & LONG_HEADER_FORM == 0 { let spin = first & SPIN_BIT != 0; if buf.remaining() < local_cid_len { @@ -572,7 +575,7 @@ impl PlainHeader { }); } - match LongHeaderType::from_byte(first, grease_quic_bit)? { + match LongHeaderType::from_byte(first)? { LongHeaderType::Initial => { let token_len = buf.get_var()? as usize; let token_start = buf.position() as usize; @@ -719,11 +722,8 @@ pub(crate) enum LongHeaderType { } impl LongHeaderType { - fn from_byte(b: u8, grease_quic_bit: bool) -> Result { + fn from_byte(b: u8) -> Result { use self::{LongHeaderType::*, LongType::*}; - if !grease_quic_bit && b & FIXED_BIT == 0 { - return Err(PacketDecodeError::InvalidHeader("fixed bit unset")); - } debug_assert!(b & LONG_HEADER_FORM != 0, "not a long packet"); Ok(match (b & 0x30) >> 4 { 0x0 => Initial,