summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLouis Williams <louis.williams@mongodb.com>2019-08-05 16:43:26 -0400
committerLouis Williams <louis.williams@mongodb.com>2019-08-05 16:43:26 -0400
commitfe4ca9897f8b8e91dc82fc15250e287da68cc83f (patch)
tree472c9f88f34238eb65bfa5efb1e27ecb3bd17d05 /src
parentdd829219438e556f4635eb5b6a31bc1158b10155 (diff)
downloadmongo-fe4ca9897f8b8e91dc82fc15250e287da68cc83f.tar.gz
SERVER-42067 Ensure key Ordering offset does not exceed the maximum number of compound index keys
Diffstat (limited to 'src')
-rw-r--r--src/mongo/bson/ordering.h3
-rw-r--r--src/mongo/db/storage/key_string_test.cpp14
2 files changed, 17 insertions, 0 deletions
diff --git a/src/mongo/bson/ordering.h b/src/mongo/bson/ordering.h
index 793e14820f5..c1052e36a90 100644
--- a/src/mongo/bson/ordering.h
+++ b/src/mongo/bson/ordering.h
@@ -57,6 +57,9 @@ public:
get(1) == -1
*/
int get(int i) const {
+ uassert(ErrorCodes::Overflow,
+ str::stream() << "Ordering offset is out of bounds: " << i,
+ i >= 0 && static_cast<size_t>(i) < kMaxCompoundIndexKeys);
return ((1 << i) & bits) ? -1 : 1;
}
diff --git a/src/mongo/db/storage/key_string_test.cpp b/src/mongo/db/storage/key_string_test.cpp
index 0a4df927404..826b3130684 100644
--- a/src/mongo/db/storage/key_string_test.cpp
+++ b/src/mongo/db/storage/key_string_test.cpp
@@ -212,6 +212,20 @@ TEST(TypeBitsTest, AppendLotsOfZeroTypeBits) {
ASSERT(!typeBits.isLongEncoding());
}
+TEST_F(KeyStringBuilderTest, TooManyElementsInCompoundKey) {
+ // Construct an illegal KeyString with more than the limit of 32 elements in a compound index
+ // key. Encode 33 kBoolTrue ('o') values.
+ const char* data = "ooooooooooooooooooooooooooooooooo";
+ const size_t size = 33;
+
+ KeyString::Builder ks(KeyString::Version::V1);
+ ks.resetFromBuffer(data, size);
+
+ ASSERT_THROWS_CODE(KeyString::toBsonSafe(data, size, ALL_ASCENDING, ks.getTypeBits()),
+ AssertionException,
+ ErrorCodes::Overflow);
+}
+
TEST_F(KeyStringBuilderTest, Simple1) {
BSONObj a = BSON("" << 5);
BSONObj b = BSON("" << 6);