From 446cd72e38b079ccd0c867138044e073e87ca03c Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Mon, 21 Jul 2025 12:18:35 +0200 Subject: [PATCH] proto: fix NewConnectionId size bound --- quinn-proto/src/connection/mod.rs | 4 ++-- quinn-proto/src/frame.rs | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/quinn-proto/src/connection/mod.rs b/quinn-proto/src/connection/mod.rs index 0152d9b81..a877421a5 100644 --- a/quinn-proto/src/connection/mod.rs +++ b/quinn-proto/src/connection/mod.rs @@ -28,7 +28,7 @@ use crate::{ coding::BufMutExt, config::{ServerConfig, TransportConfig}, crypto::{self, KeyPair, Keys, PacketKey}, - frame::{self, Close, Datagram, FrameStruct, NewToken}, + frame::{self, Close, Datagram, FrameStruct, NewConnectionId, NewToken}, packet::{ FixedLengthConnectionIdParser, Header, InitialHeader, InitialPacket, LongType, Packet, PacketNumber, PartialDecode, SpaceId, @@ -3334,7 +3334,7 @@ impl Connection { } // NEW_CONNECTION_ID - while buf.len() + 44 < max_size { + while buf.len() + NewConnectionId::SIZE_BOUND < max_size { let issued = match space.pending.new_cids.pop() { Some(x) => x, None => break, diff --git a/quinn-proto/src/frame.rs b/quinn-proto/src/frame.rs index 21fe0340c..01d9a0264 100644 --- a/quinn-proto/src/frame.rs +++ b/quinn-proto/src/frame.rs @@ -884,6 +884,10 @@ impl NewConnectionId { } } +impl FrameStruct for NewConnectionId { + const SIZE_BOUND: usize = 1 + 8 + 8 + 1 + MAX_CID_SIZE + RESET_TOKEN_SIZE; +} + /// Smallest number of bytes this type of frame is guaranteed to fit within. pub(crate) const RETIRE_CONNECTION_ID_SIZE_BOUND: usize = 9;