Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -388,4 +388,6 @@ _site
APKBUILD

# Temporary package download folder by validation script
msquic-packages/
msquic-packages/
_codeql_build_dir/
_codeql_detected_source_root
4 changes: 2 additions & 2 deletions src/core/cubic.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ CubicCongestionControlGetNetworkStatistics(
NetworkStatistics->IdealBytes = Connection->SendBuffer.IdealBytes;
NetworkStatistics->SmoothedRTT = Path->SmoothedRtt;
NetworkStatistics->CongestionWindow = Cubic->CongestionWindow;
NetworkStatistics->Bandwidth = Cubic->CongestionWindow / Path->SmoothedRtt;
NetworkStatistics->Bandwidth = Path->SmoothedRtt == 0 ? 0 : Cubic->CongestionWindow / Path->SmoothedRtt;
}

_IRQL_requires_max_(DISPATCH_LEVEL)
Expand Down Expand Up @@ -698,7 +698,7 @@ CubicCongestionControlOnDataAcknowledged(
Event.NETWORK_STATISTICS.IdealBytes = Connection->SendBuffer.IdealBytes;
Event.NETWORK_STATISTICS.SmoothedRTT = Path->SmoothedRtt;
Event.NETWORK_STATISTICS.CongestionWindow = Cubic->CongestionWindow;
Event.NETWORK_STATISTICS.Bandwidth = Cubic->CongestionWindow / Path->SmoothedRtt;
Event.NETWORK_STATISTICS.Bandwidth = Path->SmoothedRtt == 0 ? 0 : Cubic->CongestionWindow / Path->SmoothedRtt;

QuicTraceLogConnVerbose(
IndicateDataAcked,
Expand Down
38 changes: 38 additions & 0 deletions src/core/unittest/CubicTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -769,3 +769,41 @@ TEST(CubicTest, HyStart_StateTransitions)
Cubic->HyStartState <= HYSTART_DONE);
ASSERT_GE(Cubic->CWndSlowStartGrowthDivisor, 1u);
}

//
// Test 18: OnDataAcknowledged with NetStatsEventEnabled and SmoothedRtt=0
// Scenario: Verifies that no division-by-zero occurs when NetStatsEventEnabled is TRUE
// and an ACK is processed before SmoothedRtt has been set (SmoothedRtt=0).
//
TEST(CubicTest, OnDataAcknowledged_NetStatsEventDivByZero)
{
QUIC_CONNECTION Connection;
QUIC_SETTINGS_INTERNAL Settings{};
Settings.InitialWindowPackets = 10;
Settings.SendIdleTimeoutMs = 1000;

InitializeMockConnection(Connection, 1280);
Connection.Settings.NetStatsEventEnabled = TRUE;
// SmoothedRtt is 0 by default (from InitializeMockConnection)

CubicCongestionControlInitialize(&Connection.CongestionControl, &Settings);

QUIC_CONGESTION_CONTROL_CUBIC* Cubic = &Connection.CongestionControl.Cubic;
Cubic->BytesInFlight = 5000;

QUIC_ACK_EVENT AckEvent;
CxPlatZeroMemory(&AckEvent, sizeof(AckEvent));
AckEvent.TimeNow = 1000000;
AckEvent.LargestAck = 5;
AckEvent.LargestSentPacketNumber = 10;
AckEvent.NumRetransmittableBytes = 1000;
AckEvent.NumTotalAckedRetransmittableBytes = 1000;
AckEvent.SmoothedRtt = 0; // No RTT sample yet
AckEvent.MinRtt = 0;
AckEvent.MinRttValid = FALSE;
AckEvent.AckedPackets = NULL;

// Should not crash with division-by-zero when SmoothedRtt=0
Connection.CongestionControl.QuicCongestionControlOnDataAcknowledged(
&Connection.CongestionControl, &AckEvent);
}