Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-45279

GranularityRounder can get stuck in loop when rounding infinity

    XMLWordPrintableJSON

Details

    • Fully Compatible
    • ALL
    • v4.2, v4.0, v3.6
    • 23

    Description

      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).

      Attachments

        Issue Links

          Activity

            People

              sophie.saskin@mongodb.com Sophie Saskin
              ian.boros@mongodb.com Ian Boros
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: