diff options
author | Louis Williams <louis.williams@mongodb.com> | 2019-08-05 16:41:31 -0400 |
---|---|---|
committer | Louis Williams <louis.williams@mongodb.com> | 2019-08-05 16:41:31 -0400 |
commit | dd829219438e556f4635eb5b6a31bc1158b10155 (patch) | |
tree | 8b49717695da0c50d2e369660b8bee42ad9d22d6 /src/mongo/db/storage/key_string_test.cpp | |
parent | 8c083bf34d40ff64449387378d15b36462ef6f6f (diff) | |
download | mongo-dd829219438e556f4635eb5b6a31bc1158b10155.tar.gz |
SERVER-42069 uassert when decimal positive infinity is encoded in KeyString V0
Diffstat (limited to 'src/mongo/db/storage/key_string_test.cpp')
-rw-r--r-- | src/mongo/db/storage/key_string_test.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/mongo/db/storage/key_string_test.cpp b/src/mongo/db/storage/key_string_test.cpp index b55d7e32a63..0a4df927404 100644 --- a/src/mongo/db/storage/key_string_test.cpp +++ b/src/mongo/db/storage/key_string_test.cpp @@ -619,6 +619,23 @@ TEST_F(KeyStringBuilderTest, DoubleInvalidIntegerPartV0) { 31209); } +TEST_F(KeyStringBuilderTest, InvalidInfinityDecimalV0) { + // Encode a Decimal positive infinity in a V1 keystring. + mongo::KeyString::Builder ks( + mongo::KeyString::Version::V1, BSON("" << Decimal128::kPositiveInfinity), ALL_ASCENDING); + + // Construct V0 type bits that indicate a NumberDecimal has been encoded. + mongo::KeyString::TypeBits tb(mongo::KeyString::Version::V0); + tb.appendNumberDecimal(); + + // The conversion to BSON will fail because Decimal positive infinity cannot be encoded with V0 + // type bits. + ASSERT_THROWS_CODE( + mongo::KeyString::toBsonSafe(ks.getBuffer(), ks.getSize(), ALL_ASCENDING, tb), + AssertionException, + 31231); +} + TEST_F(KeyStringBuilderTest, LotsOfNumbers1) { for (int i = 0; i < 64; i++) { int64_t x = 1LL << i; |