diff options
author | Kyle Suarez <kyle.suarez@mongodb.com> | 2017-10-23 17:31:25 -0400 |
---|---|---|
committer | Kyle Suarez <kyle.suarez@mongodb.com> | 2017-10-23 17:31:54 -0400 |
commit | dbe347e2ec54858a39a2b4c59d5812214b4b94cd (patch) | |
tree | 46cc71453270c3df1daeca448a23d13c95c3b1fb /src/mongo/db/matcher/expression_parser.cpp | |
parent | ec7af3523d4aa5130c56a05d76169755d9b5a611 (diff) | |
download | mongo-dbe347e2ec54858a39a2b4c59d5812214b4b94cd.tar.gz |
SERVER-31623 MatcherTypeSet must not cast large doubles to int
Diffstat (limited to 'src/mongo/db/matcher/expression_parser.cpp')
-rw-r--r-- | src/mongo/db/matcher/expression_parser.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/mongo/db/matcher/expression_parser.cpp b/src/mongo/db/matcher/expression_parser.cpp index 0cd9ec13a53..6e7098a9b75 100644 --- a/src/mongo/db/matcher/expression_parser.cpp +++ b/src/mongo/db/matcher/expression_parser.cpp @@ -179,6 +179,21 @@ StatusWith<long long> MatchExpressionParser::parseIntegerElementToLong(BSONEleme return number; } +StatusWith<int> MatchExpressionParser::parseIntegerElementToInt(BSONElement elem) { + auto parsedLong = MatchExpressionParser::parseIntegerElementToLong(elem); + if (!parsedLong.isOK()) { + return parsedLong.getStatus(); + } + + auto valueLong = parsedLong.getValue(); + if (valueLong < std::numeric_limits<int>::min() || + valueLong > std::numeric_limits<int>::max()) { + return {ErrorCodes::FailedToParse, + str::stream() << "Cannot represent " << elem << " in an int"}; + } + return static_cast<int>(valueLong); +} + namespace { // Forward declarations. |