Repository navigation
Keep bootstrap confidence interval indices in range - #3216
Merged
Merged
Conversation
When all jackknife estimates are equal, the acceleration was computed as 0 / 0, the adjusted quantiles became NaN and std::lround(NaN) gave LONG_MIN. The upper index was only clamped from above, so it ended up as a huge size_t and resample[hi] read out of bounds. With a 64-bit long this happens to wrap around to resample[0], with a 32-bit long (MinGW) it crashes. Treat zero jackknife variance as zero acceleration, and clamp both indices to [0, n - 1], falling back to the ends of the resample if the quantile is still NaN. Fixes catchorg#3214
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## devel #3216 +/- ##
==========================================
+ Coverage 91.18% 91.42% +0.24%
==========================================
Files 205 205
Lines 9101 9104 +3
==========================================
+ Hits 8298 8323 +25
+ Misses 803 781 -22 🚀 New features to boost your workflow:
|
Member
|
Thanks |
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.
Detail::bootstrap() could index past the end of the resample, as reported in #3214.
If all jackknife estimates are equal, sum_squares is 0 and the acceleration is 0 / 0 = NaN. That makes a1/a2 NaN, std::lround(NaN) returns LONG_MIN, and since hi was only clamped from above it becomes a huge size_t. On Linux with a 64-bit long the index times sizeof(double) wraps around to resample[0], so the upper bound silently comes out below the point estimate; with a 32-bit long (MinGW, as in the issue) it is a real out-of-bounds read and crashes. The same thing happens when every resampled estimate is below the point estimate and the acceleration is non-zero, because bias is then infinite and a(b) turns into inf/inf.
Changes:
Added a test case to InternalBenchmark.tests.cpp that calls bootstrap() with both inputs. Before the change it fails with upper_bound 22.0 == 24 and 0.5 == 2 (the wrapped-around resample[0]); with it, it passes. Approval baselines are updated for the new test case, and the full ctest run passes on Linux (GCC 14).