diff options
author | Svilen Mihaylov <svilen.mihaylov@mongodb.com> | 2020-05-05 10:18:39 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-05-15 19:21:56 +0000 |
commit | 2c0306062f074fb35c0554e577401227a45ad811 (patch) | |
tree | 16aef83008c555e58e92af2b2b9b826471234fba /src/mongo/db/geo | |
parent | 26cff8f010cac091c17d7373f8ead0e8c73ee6f7 (diff) | |
download | mongo-2c0306062f074fb35c0554e577401227a45ad811.tar.gz |
SERVER-47994 Fix for numerical overflow in GeoHash
Diffstat (limited to 'src/mongo/db/geo')
-rw-r--r-- | src/mongo/db/geo/hash.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/mongo/db/geo/hash.cpp b/src/mongo/db/geo/hash.cpp index 41c6801bf63..c1170efd57e 100644 --- a/src/mongo/db/geo/hash.cpp +++ b/src/mongo/db/geo/hash.cpp @@ -687,21 +687,30 @@ Status GeoHashConverter::parseParameters(const BSONObj& paramDoc, << "but " << params->bits << " bits were specified"); } - if (params->min >= params->max) { + const bool rangeValid = params->min < params->max; + if (!rangeValid || std::isinf(params->min) || std::isinf(params->max)) { return Status(ErrorCodes::InvalidOptions, str::stream() << "region for hash must be valid and have positive area, " << "but [" << params->min << ", " << params->max << "] " << "was specified"); } - double numBuckets = (1024 * 1024 * 1024 * 4.0); + constexpr double numBuckets = 4.0 * 1024 * 1024 * 1024; params->scaling = numBuckets / (params->max - params->min); + const bool scalingValid = params->scaling > 0; + if (!scalingValid || std::isinf(params->scaling)) { + return Status(ErrorCodes::InvalidOptions, + str::stream() + << "range [" << params->min << ", " << params->max << "] is too small."); + } return Status::OK(); } GeoHashConverter::GeoHashConverter(const Parameters& params) : _params(params) { init(); + uassert( + 4799400, "Invalid GeoHashConverter parameters", _params.max - _params.min >= _error / 2); } void GeoHashConverter::init() { |