diff options
author | Geert Bosch <geert@mongodb.com> | 2018-01-10 20:14:47 -0500 |
---|---|---|
committer | Geert Bosch <geert@mongodb.com> | 2018-01-12 19:07:57 -0500 |
commit | 4e4261cd0efc5fc9e0b2b9f9b787e7b6bc12295f (patch) | |
tree | de552694a1e97dd83c15ac15d4273ad59380b245 | |
parent | f25cab34c54e87de7983f801cd3ee50395366ced (diff) | |
download | mongo-4e4261cd0efc5fc9e0b2b9f9b787e7b6bc12295f.tar.gz |
SERVER-32641 uassert, not dassert, for too many KeyString type bits
-rw-r--r-- | src/mongo/db/storage/key_string.h | 5 | ||||
-rw-r--r-- | src/mongo/db/storage/key_string_test.cpp | 17 |
2 files changed, 21 insertions, 1 deletions
diff --git a/src/mongo/db/storage/key_string.h b/src/mongo/db/storage/key_string.h index 6f7a6baebf2..c0857ca3180 100644 --- a/src/mongo/db/storage/key_string.h +++ b/src/mongo/db/storage/key_string.h @@ -40,6 +40,7 @@ #include "mongo/bson/timestamp.h" #include "mongo/db/record_id.h" #include "mongo/platform/decimal128.h" +#include "mongo/util/assert_util.h" namespace mongo { @@ -246,7 +247,9 @@ public: return _buf[0] & 0x7f; } void setSizeByte(uint8_t size) { - dassert(size < kMaxBytesNeeded); + // This error can only occur in cases where the key is not only too long, but also + // has too many fields requiring type bits. + uassert(ErrorCodes::KeyTooLong, "The key is too long", size < kMaxBytesNeeded); _buf[0] = 0x80 | size; } diff --git a/src/mongo/db/storage/key_string_test.cpp b/src/mongo/db/storage/key_string_test.cpp index 3f9530a8bcc..8efd5ff7197 100644 --- a/src/mongo/db/storage/key_string_test.cpp +++ b/src/mongo/db/storage/key_string_test.cpp @@ -1161,6 +1161,23 @@ TEST_F(KeyStringTest, RecordIds) { } } +TEST_F(KeyStringTest, KeyWithTooManyTypeBitsCausesUassert) { + BSONObj obj; + { + BSONObjBuilder builder; + { + BSONArrayBuilder array(builder.subarrayStart("x")); + auto zero = BSON("" << 0.0); + for (int i = 0; i < 1016; i++) + array.append(zero.firstElement()); + } + + obj = builder.obj(); + } + KeyString key(version); + ASSERT_THROWS_CODE(key.resetToKey(obj, ONE_ASCENDING), DBException, ErrorCodes::KeyTooLong); +} + namespace { const uint64_t kMinPerfMicros = 20 * 1000; const uint64_t kMinPerfSamples = 50 * 1000; |