diff options
author | Paolo Polato <paolo.polato@mongodb.com> | 2022-09-12 08:52:40 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-11-03 16:51:52 +0000 |
commit | a80813750a255a19690ef3335438091415f8b525 (patch) | |
tree | e54b69f5c9a4676260fbf91156018eab758d8d16 | |
parent | 8ed32b5c2c68ebe7f8ae2ebe8d23f36037a17dea (diff) | |
download | mongo-a80813750a255a19690ef3335438091415f8b525.tar.gz |
SERVER-68126 Check constraints for maxChunkSize param in auto/splitVector commands
(cherry picked from commit 50b526fecf6e13b2ac8541b69564f368ac17a8ac)
-rw-r--r-- | src/mongo/db/s/auto_split_vector_command.cpp | 10 | ||||
-rw-r--r-- | src/mongo/db/s/split_vector_command.cpp | 15 |
2 files changed, 23 insertions, 2 deletions
diff --git a/src/mongo/db/s/auto_split_vector_command.cpp b/src/mongo/db/s/auto_split_vector_command.cpp index 32275403eff..58b62c0a135 100644 --- a/src/mongo/db/s/auto_split_vector_command.cpp +++ b/src/mongo/db/s/auto_split_vector_command.cpp @@ -39,6 +39,9 @@ namespace mongo { namespace { +static constexpr int64_t kSmallestChunkSizeBytesSupported = 1024 * 1024; +static constexpr int64_t kBiggestChunkSizeBytesSupported = 1024 * 1024 * 1024; + class AutoSplitVectorCommand final : public TypedCommand<AutoSplitVectorCommand> { public: AllowedOnSecondary secondaryAllowed(ServiceContext*) const override { @@ -67,6 +70,13 @@ public: const auto& req = request(); + uassert(ErrorCodes::ErrorCodes::InvalidOptions, + str::stream() << "maxChunksSizeBytes must lie within the range [" + << kSmallestChunkSizeBytesSupported / (1024 * 1024) << "MB, " + << kBiggestChunkSizeBytesSupported / (1024 * 1024) << "MB]", + req.getMaxChunkSizeBytes() >= kSmallestChunkSizeBytesSupported && + req.getMaxChunkSizeBytes() <= kBiggestChunkSizeBytesSupported); + auto splitKeys = autoSplitVector(opCtx, ns(), req.getKeyPattern(), diff --git a/src/mongo/db/s/split_vector_command.cpp b/src/mongo/db/s/split_vector_command.cpp index 9af279ce4ef..0f5fbc8bcee 100644 --- a/src/mongo/db/s/split_vector_command.cpp +++ b/src/mongo/db/s/split_vector_command.cpp @@ -128,9 +128,20 @@ public: BSONElement maxSizeBytesElem = jsobj["maxChunkSizeBytes"]; // Use maxChunkSize if present otherwise maxChunkSizeBytes if (maxSizeElem.isNumber()) { - maxChunkSizeBytes = maxSizeElem.numberLong() * 1 << 20; + long long maxChunkSizeMB = maxSizeElem.safeNumberLong(); + // Check before converting to bytes to avoid overflow errors. + if (maxChunkSizeMB < 1 || maxChunkSizeMB > 1024) { + errmsg = "The specified max chunk size must lie within the range [1MB, 1024MB]"; + return false; + } + + maxChunkSizeBytes = maxChunkSizeMB << 20; } else if (maxSizeBytesElem.isNumber()) { - maxChunkSizeBytes = maxSizeBytesElem.numberLong(); + maxChunkSizeBytes = maxSizeBytesElem.safeNumberLong(); + if (*maxChunkSizeBytes < 1024 * 1024 || *maxChunkSizeBytes > 1024 * 1024 * 1024) { + errmsg = "The specified max chunk size must lie within the range [1MB, 1024MB]"; + return false; + } } auto statusWithSplitKeys = splitVector(opCtx, |