diff options
Diffstat (limited to 'src/mongo/db/pipeline/document_source_bucket_test.cpp')
| -rw-r--r-- | src/mongo/db/pipeline/document_source_bucket_test.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/mongo/db/pipeline/document_source_bucket_test.cpp b/src/mongo/db/pipeline/document_source_bucket_test.cpp index 1036c456ef3..e7702d58d28 100644 --- a/src/mongo/db/pipeline/document_source_bucket_test.cpp +++ b/src/mongo/db/pipeline/document_source_bucket_test.cpp @@ -79,7 +79,8 @@ public: // Serialize the DocumentSourceGroup and DocumentSourceSort from $bucket so that we can // check the explain output to make sure $group and $sort have the correct fields. - auto explain = ExplainOptions::Verbosity::kQueryPlanner; + auto explain = + SerializationOptions{boost::make_optional(ExplainOptions::Verbosity::kQueryPlanner)}; vector<Value> explainedStages; groupStage->serializeToArray(explainedStages, explain); sortStage->serializeToArray(explainedStages, explain); @@ -227,9 +228,35 @@ TEST_F(BucketReturnsGroupAndSort, BucketSucceedsWithMultipleBoundaryValues) { testCreateFromBsonResult(spec, expectedGroupExplain); } +TEST_F(BucketReturnsGroupAndSort, BucketWithEmptyGroupByStrDoesNotAccessPastEndOfString) { + // Verify that {groupBy: ''} is rejected _without_ attempting to read past the end of the empty + // string. + const auto spec = + fromjson("{$bucket : {groupBy : '', boundaries : [ 1, 5, 8 ], default : 'other'}}"); + + // Under a debug build, this would previously fail if an empty str for groupBy led to access + // past the end of the string, with pos() > size() in StringData::operator[]. + // Verify that this reaches the intended uassert, rejecting the empty string, _without_ first + // trying to read past the end of the string. + ASSERT_THROWS_CODE(DocumentSourceBucket::createFromBson(spec.firstElement(), getExpCtx()), + AssertionException, + 40202); +} + +/* + * Override the stub interface to allow full execution in these tests. + */ +class ExecutableStubMongoProcessInterface : public StubMongoProcessInterface { + bool isExpectedToExecuteQueries() override { + return true; + } +}; + class InvalidBucketSpec : public AggregationContextFixture { public: list<intrusive_ptr<DocumentSource>> createBucket(BSONObj bucketSpec) { + getExpCtx()->mongoProcessInterface = + std::make_unique<ExecutableStubMongoProcessInterface>(); auto sources = DocumentSourceBucket::createFromBson(bucketSpec.firstElement(), getExpCtx()); return sources; } |
