Fix division by zero in cubic.c NetStats bandwidth calculation when SmoothedRtt is 0#5888
Fix division by zero in cubic.c NetStats bandwidth calculation when SmoothedRtt is 0#5888
Conversation
Co-authored-by: saikat107 <2145576+saikat107@users.noreply.github.com> Agent-Logs-Url: https://github.com/microsoft/msquic/sessions/09569349-ecf1-4c4c-96d9-f94d065ab360
|
@copilot add test case(s) in the src/core/unittest/CubicTest.cpp to illustrate the change |
Co-authored-by: saikat107 <2145576+saikat107@users.noreply.github.com> Agent-Logs-Url: https://github.com/microsoft/msquic/sessions/75f472a3-7faa-4236-bb73-dce3bf94d089
Added two test cases in commit 2bb5c96:
Both tests are placed alongside the existing |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5888 +/- ##
==========================================
- Coverage 86.23% 84.78% -1.45%
==========================================
Files 60 60
Lines 18732 18732
==========================================
- Hits 16153 15882 -271
- Misses 2579 2850 +271 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
guhetier
left a comment
There was a problem hiding this comment.
I am not sure we can ever reach that point in the code without having at least one RTT sample (since we got an Ack, we likely updated the RTT right before), but since the path is not trivial, the validation won't hurt and maybe avoid an issue in a corner case.
Thanks for the PR
Description
Bandwidth = CongestionWindow / SmoothedRttincubic.ccrashes withSTATUS_INTEGER_DIVIDE_BY_ZEROwhen an ACK is processed before the first RTT sample is available (SmoothedRtt == 0). This affects two code paths:CubicCongestionControlGetNetworkStatistics— queried bandwidth when RTT not yet sampledCubicCongestionControlOnDataAcknowledged—NetStatsEventEnabledpath on early ACKBoth sites now return
Bandwidth = 0whenSmoothedRtt == 0:Testing
Two new unit tests were added to
src/core/unittest/CubicTest.cppto cover both fixed paths:CubicTest.GetNetworkStatistics_ZeroSmoothedRtt_BandwidthIsZero— callsGetNetworkStatisticswithSmoothedRtt == 0and assertsBandwidth == 0without crashing.CubicTest.OnDataAcknowledged_NetStats_ZeroSmoothedRtt_BandwidthIsZero— fires an ACK withNetStatsEventEnabled = TRUEandSmoothedRtt == 0and asserts no divide-by-zero crash occurs.All 52
CubicTestcases pass.Documentation
No documentation impact.
Original prompt
⚡ Quickly spin up Copilot coding agent tasks from anywhere on your macOS or Windows machine with Raycast.