This code will loop for forever when number is the double value infinity. Repro:
diff --git a/src/mongo/db/pipeline/granularity_rounder_preferred_numbers_test.cpp b/src/mongo/db/pipeline/granularity_rounder_preferred_numbers_test.cpp index e4d8600b40..ae97faa6d2 100644 --- a/src/mongo/db/pipeline/granularity_rounder_preferred_numbers_test.cpp +++ b/src/mongo/db/pipeline/granularity_rounder_preferred_numbers_test.cpp @@ -528,5 +528,17 @@ TEST(GranularityRounderPreferredNumbersTest, ShouldFailOnRoundingNegativeNumber) ASSERT_THROWS_CODE(rounder->roundDown(negativeNumber), AssertionException, 40268); } } + +TEST(GranularityRounderPreferredNumbersTest, infinity) { + auto rounder = + GranularityRounder::getGranularityRounder(new ExpressionContextForTest(), "E192"); + + Value inf = Value(std::numeric_limits<double>::infinity()); + rounder->roundUp(inf); + + ASSERT_EQ(true, false); // never get here +} } // namespace } // namespace mongo
Note that the right hand side will eventually get to infinity, but infinity won't compare less than or greater than itself so it just spins in the loop.
It's possible to trigger this bug through aggregate() as well (the fuzzer has caught this for us).
- is duplicated by
-
SERVER-45462 $bucketAuto's granularity field should handle Infinity
- Closed