pelikan-io / rustcommon

Common Rust library
Apache License 2.0
26 stars 13 forks source link

fix: histogram panics #28

Closed brayniac closed 1 year ago

brayniac commented 1 year ago

Addresses two panic cases within this crate and fixes the percentiles()` function to return the correct results.

There's a wrapping math operation which occurs when calculating the upper bound of the highest bucket when the histogram is configured to cover the entired 64bit range. This is addressed by returning the histogram's max value if the bucket is the last bucket.

Additionally, as reported in #25 we perform a bounds check after we index into an array in the percentiles() function. This will reliably cause a panic. However, there are also issues with the returned results after correcting the panic condition.

Fixes the logic in the percentiles() function to both avoid out of bounds access and return the correct results.