diff options
author | Robert Guo <robert.guo@10gen.com> | 2016-05-10 12:31:51 -0400 |
---|---|---|
committer | Robert Guo <robert.guo@10gen.com> | 2016-05-16 17:13:31 -0400 |
commit | e752711398860b80e1acfee13ec277c77534977b (patch) | |
tree | 1e14e74c82d895b4f3a05a25fe8f332e2f2845f7 | |
parent | 61965e5792b29e3aaa04421e848731f1f2457766 (diff) | |
download | mongo-e752711398860b80e1acfee13ec277c77534977b.tar.gz |
SERVER-24116 fix KeyString's parsing of strings with leading null
(cherry picked from commit 6a0904bd38a2deb2de127865943d57ca7cfa6927)
-rw-r--r-- | src/mongo/db/storage/key_string.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/storage/key_string_test.cpp | 5 |
2 files changed, 9 insertions, 1 deletions
diff --git a/src/mongo/db/storage/key_string.cpp b/src/mongo/db/storage/key_string.cpp index 00dc9e067d9..afd0c512aa4 100644 --- a/src/mongo/db/storage/key_string.cpp +++ b/src/mongo/db/storage/key_string.cpp @@ -248,8 +248,11 @@ string readInvertedCString(BufReader* reader) { string readInvertedCStringWithNuls(BufReader* reader) { std::string out; + bool firstPass = true; do { - if (!out.empty()) { + if (firstPass) { + firstPass = false; + } else { // If this isn't our first pass through the loop it means we hit an NUL byte // encoded as "\xFF\00" in our inverted string. reader->skip(1); diff --git a/src/mongo/db/storage/key_string_test.cpp b/src/mongo/db/storage/key_string_test.cpp index 9dfa3104040..409ffb82bcf 100644 --- a/src/mongo/db/storage/key_string_test.cpp +++ b/src/mongo/db/storage/key_string_test.cpp @@ -389,6 +389,7 @@ const std::vector<BSONObj>& getInterestingElements() { // These are used to test strings that include NUL bytes. const StringData ball("ball", StringData::LiteralTag()); const StringData ball00n("ball\0\0n", StringData::LiteralTag()); + const StringData zeroBall("\0ball", StringData::LiteralTag()); elements.push_back(BSON("" << 1)); elements.push_back(BSON("" << 1.0)); @@ -414,8 +415,10 @@ const std::vector<BSONObj>& getInterestingElements() { << "aaa")); elements.push_back(BSON("" << "AAA")); + elements.push_back(BSON("" << zeroBall)); elements.push_back(BSON("" << ball)); elements.push_back(BSON("" << ball00n)); + elements.push_back(BSON("" << BSONSymbol(zeroBall))); elements.push_back(BSON("" << BSONSymbol(ball))); elements.push_back(BSON("" << BSONSymbol(ball00n))); elements.push_back(BSON("" << BSON("a" << 5))); @@ -427,6 +430,7 @@ const std::vector<BSONObj>& getInterestingElements() { elements.push_back(BSON("" << OID("abcdefabcdefabcdefabcdef"))); elements.push_back(BSON("" << Date_t::fromMillisSinceEpoch(123))); elements.push_back(BSON("" << BSONCode("abc_code"))); + elements.push_back(BSON("" << BSONCode(zeroBall))); elements.push_back(BSON("" << BSONCode(ball))); elements.push_back(BSON("" << BSONCode(ball00n))); elements.push_back(BSON("" << BSONCodeWScope("def_code1", @@ -438,6 +442,7 @@ const std::vector<BSONObj>& getInterestingElements() { elements.push_back(BSON("" << BSONCodeWScope("def_code2", BSON("x_scope" << "b")))); + elements.push_back(BSON("" << BSONCodeWScope(zeroBall, BSON("a" << 1)))); elements.push_back(BSON("" << BSONCodeWScope(ball, BSON("a" << 1)))); elements.push_back(BSON("" << BSONCodeWScope(ball00n, BSON("a" << 1)))); elements.push_back(BSON("" << true)); |