diff options
author | Kevin Albertson <kevin.albertson@mongodb.com> | 2023-01-09 19:21:47 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-01-09 20:13:29 +0000 |
commit | b4119be75bb8f31da7e8f28bb4e3f881f3bc5027 (patch) | |
tree | d225dcff45039a0c39aa81a11b4cd83928c27c89 | |
parent | d07d44357f54f59c6f2196b7006ba8059c1e5a0f (diff) | |
download | mongo-b4119be75bb8f31da7e8f28bb4e3f881f3bc5027.tar.gz |
SERVER-72621 truncate v_prime2
-rw-r--r-- | src/mongo/crypto/fle_crypto.cpp | 5 | ||||
-rw-r--r-- | src/mongo/crypto/fle_crypto_test.cpp | 6 |
2 files changed, 11 insertions, 0 deletions
diff --git a/src/mongo/crypto/fle_crypto.cpp b/src/mongo/crypto/fle_crypto.cpp index c5bda150f5f..70c37d22ce7 100644 --- a/src/mongo/crypto/fle_crypto.cpp +++ b/src/mongo/crypto/fle_crypto.cpp @@ -4004,6 +4004,11 @@ OSTType_Decimal128 getTypeInfoDecimal128(Decimal128 value, // // Returns 3141.0 Decimal128 v_prime2 = v_prime.subtract(min.get()).scale(precision.get()); + // Round the number down again. min may have a fractional value with more decimal places + // than the precision (e.g. .001). Subtracting min may have resulted in v_prime2 with + // a non-zero fraction. v_prime2 is expected to have no fractional value when + // converting to int128. + v_prime2 = v_prime2.round(Decimal128::kRoundTowardZero); invariant(v_prime2.logarithm(Decimal128(2)).isLess(Decimal128(128))); diff --git a/src/mongo/crypto/fle_crypto_test.cpp b/src/mongo/crypto/fle_crypto_test.cpp index 538211edd9f..e655d10cd2b 100644 --- a/src/mongo/crypto/fle_crypto_test.cpp +++ b/src/mongo/crypto/fle_crypto_test.cpp @@ -2768,6 +2768,12 @@ TEST(RangeTest, Decimal128_Bounds_Precision) { ASSERT_EIBB(5E-30, 10E-30, 1E-30, 35, boost::multiprecision::uint128_t("400000")); + // Test a range that requires > 64 bits. + ASSERT_EIBB(5, "18446744073709551616", ".1", 1, 49) + // Test a range that requires > 64 bits. + // min has more places after the decimal than precision. + ASSERT_EIBB(5, "18446744073709551616", ".01", 1, 49) + #undef ASSERT_EIBB #undef ASSERT_EIBB_OVERFLOW } |