diff options
author | Jennifer Peshansky <jennifer.peshansky@mongodb.com> | 2021-10-13 20:26:26 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-10-20 20:08:32 +0000 |
commit | cb1e9d3b1e5c964d3a54fd9f6d85da817e7d5372 (patch) | |
tree | 2ad4be488ab301265d5137e9a4cbc7946eb5b136 /src | |
parent | 2fb2a7cf46a3e438a83670d08c91ae8e7981b48a (diff) | |
download | mongo-cb1e9d3b1e5c964d3a54fd9f6d85da817e7d5372.tar.gz |
SERVER-60588 Don't attempt to coerce a double product to long
(cherry picked from commit d0a023d1cba8782c761890c20752ecf494d22a62)
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/pipeline/expression.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/mongo/db/pipeline/expression.cpp b/src/mongo/db/pipeline/expression.cpp index f35cd8c81b3..8fcd1fa7d99 100644 --- a/src/mongo/db/pipeline/expression.cpp +++ b/src/mongo/db/pipeline/expression.cpp @@ -3123,11 +3123,15 @@ public: } else { doubleProduct *= val.coerceToDouble(); - if (!std::isfinite(val.coerceToDouble()) || - overflow::mul(longProduct, val.coerceToLong(), &longProduct)) { - // The number is either Infinity or NaN, or the 'longProduct' would have - // overflowed, so we're abandoning it. - productType = NumberDouble; + if (productType != NumberDouble) { + // If `productType` is not a double, it must be one of the integer types, so we + // attempt to update `longProduct`. + if (!std::isfinite(val.coerceToDouble()) || + overflow::mul(longProduct, val.coerceToLong(), &longProduct)) { + // The multiplier is either Infinity or NaN, or the `longProduct` would + // have overflowed, so we're abandoning it. + productType = NumberDouble; + } } } } |