Skip to content

Fix division by zero in CUBIC NetStats Bandwidth computation when SmoothedRtt is 0#5838

Draft
Copilot wants to merge 6 commits intomainfrom
copilot/fix-division-by-zero-netstats
Draft

Fix division by zero in CUBIC NetStats Bandwidth computation when SmoothedRtt is 0#5838
Copilot wants to merge 6 commits intomainfrom
copilot/fix-division-by-zero-netstats

Conversation

Copy link
Contributor

Copilot AI commented Mar 3, 2026

Description

CongestionWindow / SmoothedRtt in two CUBIC paths crashes with STATUS_INTEGER_DIVIDE_BY_ZERO when an ACK or stats query arrives before the first RTT sample is recorded (SmoothedRtt == 0).

  • cubic.cCubicCongestionControlOnDataAcknowledged: Guard the Bandwidth assignment in the NetStatsEventEnabled path against zero SmoothedRtt
  • cubic.cCubicCongestionControlGetNetworkStatistics: Same guard applied to the identical pattern
// Before (both sites)
NetworkStatistics->Bandwidth = Cubic->CongestionWindow / Path->SmoothedRtt;

// After
NetworkStatistics->Bandwidth = Path->SmoothedRtt == 0 ? 0 : Cubic->CongestionWindow / Path->SmoothedRtt;

Testing

New test CubicTest.OnDataAcknowledged_NetStatsEventDivByZero exercises the crash path: initializes a connection with NetStatsEventEnabled = TRUE and SmoothedRtt = 0, then fires an ACK event — previously causing a divide-by-zero, now returning cleanly.

Documentation

No documentation impact.

Original prompt

This section details on the original issue you should resolve

<issue_title>[DeepTest] Division by zero in OnDataAcknowledged NetStats event path</issue_title>
<issue_description>### Describe the bug
Location: src/core/cubic.c, line 701
Event.NETWORK_STATISTICS.Bandwidth = Cubic->CongestionWindow / Path->SmoothedRtt;

Root cause: Same division-by-zero pattern as #5833, but in the OnDataAcknowledged function's NetStatsEventEnabled path. If NetStatsEventEnabled is TRUE and an ACK is processed before SmoothedRtt is set, the same crash occurs.

Affected OS

  • Windows
  • Linux
  • macOS
  • Other (specify below)

Additional OS information

No response

MsQuic version

main

Steps taken to reproduce bug

  1. Add the following test in src/core/unittest/CubicTest.cpp
TEST(CubicTest, DeepTest_Bug_NetStatsEventDivByZero)
{
    QUIC_CONNECTION Connection;
    QUIC_SETTINGS_INTERNAL Settings{};
    Settings.InitialWindowPackets = 10;
    Settings.SendIdleTimeoutMs = 1000;

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

    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
    AckEvent.MinRtt = 0;
    AckEvent.MinRttValid = FALSE;
    AckEvent.AckedPackets = NULL;

    // This will crash with STATUS_INTEGER_DIVIDE_BY_ZERO
    // because Path->SmoothedRtt=0 and line 701 does: CongestionWindow / SmoothedRtt
    Connection.CongestionControl.QuicCongestionControlOnDataAcknowledged(
        &Connection.CongestionControl, &AckEvent);
}
  1. Build and run the test with filter CubicTest.DeepTest_Bug_NetStatsEventDivByZero

Expected behavior

Should not crash.

Actual outcome

STATUS_INTEGER_DIVIDE_BY_ZERO crash

Additional details

No response</issue_description>

<agent_instructions>fix and add test case</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 5 commits March 3, 2026 01:55
…tt is 0

Co-authored-by: saikat107 <2145576+saikat107@users.noreply.github.com>
Co-authored-by: saikat107 <2145576+saikat107@users.noreply.github.com>
Co-authored-by: saikat107 <2145576+saikat107@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix division by zero in OnDataAcknowledged NetStats event path Fix division by zero in CUBIC NetStats Bandwidth computation when SmoothedRtt is 0 Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[DeepTest] Division by zero in OnDataAcknowledged NetStats event path

2 participants