summaryrefslogtreecommitdiff
path: root/src/mongo/crypto/encryption_fields_validation.cpp
diff options
context:
space:
mode:
authorShreyas Kalyan <shreyas.kalyan@mongodb.com>2022-10-19 18:45:29 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-10-28 17:08:17 +0000
commit0d9455e8ee5ed764aee6a514d789ae1b5ed0af03 (patch)
treeafdf0a9b77327ee7ec3b51d699d132dbf311c453 /src/mongo/crypto/encryption_fields_validation.cpp
parent9e75d3b2db979335716de2b1f6b5bb6bcf0b6f3b (diff)
downloadmongo-0d9455e8ee5ed764aee6a514d789ae1b5ed0af03.tar.gz
SERVER-69671 FLE2 range float precision: update createCollection to enforce parameter constraints
Diffstat (limited to 'src/mongo/crypto/encryption_fields_validation.cpp')
-rw-r--r--src/mongo/crypto/encryption_fields_validation.cpp35
1 files changed, 24 insertions, 11 deletions
diff --git a/src/mongo/crypto/encryption_fields_validation.cpp b/src/mongo/crypto/encryption_fields_validation.cpp
index a0debee4a89..3c370136fb3 100644
--- a/src/mongo/crypto/encryption_fields_validation.cpp
+++ b/src/mongo/crypto/encryption_fields_validation.cpp
@@ -77,7 +77,7 @@ Value coerceValueToRangeIndexTypes(Value val, BSONType fieldType) {
}
-void validateRangeIndex(BSONType fieldType, const QueryTypeConfig& query) {
+void validateRangeIndex(BSONType fieldType, QueryTypeConfig& query) {
uassert(6775201,
str::stream() << "Type '" << typeName(fieldType)
<< "' is not a supported range indexed type",
@@ -90,18 +90,31 @@ void validateRangeIndex(BSONType fieldType, const QueryTypeConfig& query) {
"The field 'sparsity' must be between 1 and 4",
query.getSparsity().value() >= 1 && query.getSparsity().value() <= 4);
+
switch (fieldType) {
case NumberDouble:
- case NumberDecimal:
- uassert(7006601,
- "The field 'min' on floating point field is invalid for range index over "
- "double/decimal fields.",
- !query.getMin().has_value());
- uassert(7006602,
- "The field 'max' on floating point field is invalid for range index over "
- "double/decimal fields.",
- !query.getMax().has_value());
- break;
+ case NumberDecimal: {
+ if (!((query.getMin().has_value() == query.getMax().has_value()) &&
+ (query.getMin().has_value() == query.getPrecision().has_value()))) {
+ uasserted(6967100,
+ str::stream() << "Precision, min, and max must all be specified "
+ << "together for floating point fields");
+ }
+
+ if (!query.getMin().has_value()) {
+ if (fieldType == NumberDouble) {
+ query.setMin(mongo::Value(std::numeric_limits<double>::min()));
+ query.setMax(mongo::Value(std::numeric_limits<double>::max()));
+ } else {
+ query.setMin(mongo::Value(Decimal128::kLargestNegative));
+ query.setMax(mongo::Value(Decimal128::kLargestPositive));
+ }
+ }
+ }
+ // We want to perform the same validation after sanitizing floating
+ // point parameters, so we call FMT_FALLTHROUGH here.
+
+ FMT_FALLTHROUGH;
case NumberInt:
case NumberLong:
case Date: {