summaryrefslogtreecommitdiff
path: root/src/mongo/bson
diff options
context:
space:
mode:
authorLouis Williams <louis.williams@mongodb.com>2020-12-07 11:26:21 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-12-07 21:05:54 +0000
commit957ddd678dbd49a96318a13e8f669567e4eba3ab (patch)
tree60b58ae8c546cf7ba919271b7bcd224f0ed1c54f /src/mongo/bson
parentaf0698b8c699f006ac463363539bdb9f61344cbd (diff)
downloadmongo-957ddd678dbd49a96318a13e8f669567e4eba3ab.tar.gz
SERVER-52929 Correctly handle compound indexes with 32 keys
Diffstat (limited to 'src/mongo/bson')
-rw-r--r--src/mongo/bson/ordering.h8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/mongo/bson/ordering.h b/src/mongo/bson/ordering.h
index d1178623f91..b7b923c9a82 100644
--- a/src/mongo/bson/ordering.h
+++ b/src/mongo/bson/ordering.h
@@ -62,7 +62,13 @@ public:
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);
+ i >= 0);
+ // Ordering only allows the first 32 fields to be inverted; any fields after the 32nd must
+ // be ascending. Return 1 to avoid a left shift a 32-bit integer by more than 31 bits, which
+ // is undefined behavior in C++.
+ if (static_cast<size_t>(i) >= kMaxCompoundIndexKeys) {
+ return 1;
+ }
return ((1u << i) & bits) ? -1 : 1;
}