diff options
author | Nick Zolnierz <nicholas.zolnierz@mongodb.com> | 2018-09-17 13:13:27 -0400 |
---|---|---|
committer | Nick Zolnierz <nicholas.zolnierz@mongodb.com> | 2018-09-19 11:23:17 -0400 |
commit | 29b72c2b5d1019b95bbdf8505eeeb92049739ca4 (patch) | |
tree | a890595c484ce277e15c8b07fd4acd7b486bfa21 /src/mongo/db/pipeline/document_source_exchange.cpp | |
parent | 86d7a754bd72f055445968f4de92c60ae7b8ae70 (diff) | |
download | mongo-29b72c2b5d1019b95bbdf8505eeeb92049739ca4.tar.gz |
SERVER-37108: Validate $exchange's number of buffers and buffer size limit to avoid OOM
Diffstat (limited to 'src/mongo/db/pipeline/document_source_exchange.cpp')
-rw-r--r-- | src/mongo/db/pipeline/document_source_exchange.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/mongo/db/pipeline/document_source_exchange.cpp b/src/mongo/db/pipeline/document_source_exchange.cpp index 49de073af73..3e990f65e43 100644 --- a/src/mongo/db/pipeline/document_source_exchange.cpp +++ b/src/mongo/db/pipeline/document_source_exchange.cpp @@ -41,6 +41,9 @@ namespace mongo { +constexpr size_t Exchange::kMaxBufferSize; +constexpr size_t Exchange::kMaxNumberConsumers; + const char* DocumentSourceExchange::getSourceName() const { return "$_internalExchange"; } @@ -71,6 +74,13 @@ Exchange::Exchange(ExchangeSpec spec, std::unique_ptr<Pipeline, PipelineDeleter> _pipeline(std::move(pipeline)) { uassert(50901, "Exchange must have at least one consumer", _spec.getConsumers() > 0); + uassert(50951, + str::stream() << "Specified exchange buffer size (" << _maxBufferSize + << ") exceeds the maximum allowable amount (" + << kMaxBufferSize + << ").", + _maxBufferSize <= kMaxBufferSize); + for (int idx = 0; idx < _spec.getConsumers(); ++idx) { _consumers.emplace_back(std::make_unique<ExchangeBuffer>()); } @@ -120,6 +130,13 @@ std::vector<std::string> Exchange::extractBoundaries( std::vector<size_t> Exchange::extractConsumerIds( const boost::optional<std::vector<std::int32_t>>& consumerIds, size_t nConsumers) { + uassert(50950, + str::stream() << "Specified number of exchange consumers (" << nConsumers + << ") exceeds the maximum allowable amount (" + << kMaxNumberConsumers + << ").", + nConsumers <= kMaxNumberConsumers); + std::vector<size_t> ret; if (!consumerIds) { |