diff options
author | Benety Goh <benety@mongodb.com> | 2021-08-18 16:45:26 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-08-18 21:39:53 +0000 |
commit | ced65a176cab202d5abf57488f777189f27d7e41 (patch) | |
tree | 14f1643c188bd88c2ddb77230f6cfa234399e388 /src/mongo/bson | |
parent | 0b7a5df7618fa848c72e817e4b18d21e01c5ca55 (diff) | |
download | mongo-ced65a176cab202d5abf57488f777189f27d7e41.tar.gz |
SERVER-57633 SERVER-48076 fix implicit long long to double conversion in BSONElement::tryCoerce()
Diffstat (limited to 'src/mongo/bson')
-rw-r--r-- | src/mongo/bson/bsonelement.h | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/mongo/bson/bsonelement.h b/src/mongo/bson/bsonelement.h index 84d8f7fb909..3502ff8a7f6 100644 --- a/src/mongo/bson/bsonelement.h +++ b/src/mongo/bson/bsonelement.h @@ -1056,7 +1056,12 @@ Status BSONElement::tryCoerce(T* out) const { if (!std::isfinite(d)) { return {ErrorCodes::BadValue, "Unable to coerce NaN/Inf to integral type"}; } - if ((d > std::numeric_limits<T>::max()) || (d < std::numeric_limits<T>::lowest())) { + // TODO(SERVER-48076): Revisit the use of the > operator for the T::max() comparison in + // the case when T is a 64 bit type. When T is a 64 bit type, this comparison should + // be >=, as the conversion rounds the the max to 2**63 which is double that cannot be + // converted. + if ((d > static_cast<double>(std::numeric_limits<T>::max())) || + (d < std::numeric_limits<T>::lowest())) { return {ErrorCodes::BadValue, "Out of bounds coercing to integral value"}; } val = static_cast<long long>(d); |