From f70b9378e15d73cdc322659730e19295d8ce47c1 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Wed, 25 Sep 2024 07:41:20 +0200 Subject: [PATCH] Extend panic when pn_len is 0 with metadata (#2134) `Connection::add_packet_number -> PacketBuilder::pn -> Encoder::encode_uint` panics when `pn_len` is `0`. These panics are seen in Firefox crash reports. To be able to find the root cause of the panic, add additional metadata. See https://github.com/mozilla/neqo/issues/2132 for details. --- neqo-transport/src/connection/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/neqo-transport/src/connection/mod.rs b/neqo-transport/src/connection/mod.rs index d8d9db2422..e0202610e5 100644 --- a/neqo-transport/src/connection/mod.rs +++ b/neqo-transport/src/connection/mod.rs @@ -2018,7 +2018,10 @@ impl Connection { // Count how many bytes in this range are non-zero. let pn_len = mem::size_of::() - usize::try_from(unacked_range.leading_zeros() / 8).unwrap(); - // pn_len can't be zero (unacked_range is > 0) + assert!( + pn_len > 0, + "pn_len can't be zero as unacked_range should be > 0, pn {pn}, largest_acknowledged {largest_acknowledged:?}, tx {tx}" + ); // TODO(mt) also use `4*path CWND/path MTU` to set a minimum length. builder.pn(pn, pn_len); pn