Repository navigation
Conversation
updateStatistics computed the Welford deltas as time.Duration. The RTT comes from the timestamp echoed in the reply, so a forged reply can give two RTTs more than ~292 years apart; their difference then wraps int64 and AvgRtt and StdDevRtt end up wrong (AvgRtt even changes sign). Compute the deltas in float64. For RTTs below 2^53 ns (about 104 days) the float64 values are exact and the truncating conversion matches the previous integer division, so normal results are unchanged. Fixes prometheus-community#240 Signed-off-by: Ahmed Laban <79754427+amlaban65@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #240
updateStatisticscomputes the Welford deltas (pkt.Rtt - p.avgRtt) astime.Duration. The RTT isreceivedAt.Sub(timestamp)with the timestamp taken from the echoed payload, so a forged reply can produce RTTs more than ~292 years apart. Their difference then wrapsint64, andAvgRtt(andStdDevRtt, which uses the same deltas) end up wrong — with the RTTs from the issue,AvgRttbecomes-2124047h47m16.85sinstead of 50 years.This change computes both deltas in
float64, as the issue suggests, and keeps the stored average as atime.Duration. For RTTs below 2^53 ns (about 104 days) thefloat64values are exact and the truncatingtime.Duration(delta / n)conversion gives the same result as the previous integer division, so the statistics for normal pings are unchanged.Testing
TestStatisticsAvgRttOverflow(the reproduction from the issue, plus aStdDevRttcheck). It fails onmainand passes with this change.TestStatisticsSunny,TestStatisticsLossyandTestStatisticsZeroDivisionstill pass with the same exact values.gofmtandgo vetare clean. I ran each test in the package individually before and after the change: the only difference is the new test going from fail to pass. Six tests that open raw ICMP sockets (e.g.TestNewPingerValid) can't run in my sandbox (socket: permission denied) and fail the same way with and without the change, so those rely on CI.