summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLouis Williams <louis.williams@mongodb.com>2021-06-17 10:41:48 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-06-29 16:25:33 +0000
commit17158bd640654e34c376e99ff30cd27d35c53847 (patch)
treeff2fad55ae4b53e989a491bdf79dd3ee7114749a
parent5a283f9b27c69cbcd6111d1a4cb1025afcc52142 (diff)
downloadmongo-17158bd640654e34c376e99ff30cd27d35c53847.tar.gz
SERVER-57492 Side-write table should not write more than KeyString
This fixes a bug where extra data in the form of uninitialized memory was being written to the index builds side writes table. This memory is never observed and only takes up space in the table. This commit also renames BufBuilder::getSize() to capacity() to conform to the STL convention and to prevent similar bugs in the future. (cherry picked from commit ba81849df916f6c417585c6cd51e6508be5001fe) (cherry picked from commit baa350cb285592702833f4f51ecc7ffbb5982080)
-rw-r--r--src/mongo/bson/bsonobjbuilder.cpp2
-rw-r--r--src/mongo/bson/util/builder.h7
-rw-r--r--src/mongo/db/index/index_build_interceptor.cpp4
3 files changed, 7 insertions, 6 deletions
diff --git a/src/mongo/bson/bsonobjbuilder.cpp b/src/mongo/bson/bsonobjbuilder.cpp
index 3b8c3774c6b..aaa8b2fafcc 100644
--- a/src/mongo/bson/bsonobjbuilder.cpp
+++ b/src/mongo/bson/bsonobjbuilder.cpp
@@ -230,7 +230,7 @@ BSONObjBuilder::~BSONObjBuilder() {
// BufBuilder but do not own it ourselves, then we must call _done to write in the
// length. Otherwise, we own this memory and its lifetime ends with us, therefore
// we can elide the write.
- if (!_doneCalled && _b.buf() && _buf.getSize() == 0) {
+ if (!_doneCalled && _b.buf() && _buf.capacity() == 0) {
_done();
}
}
diff --git a/src/mongo/bson/util/builder.h b/src/mongo/bson/util/builder.h
index 64b578faafd..4d66fdee83e 100644
--- a/src/mongo/bson/util/builder.h
+++ b/src/mongo/bson/util/builder.h
@@ -273,15 +273,16 @@ public:
str.copyTo(grow(len), includeEndingNull);
}
- /** @return length of current std::string */
+ /** Returns the length of data in the current buffer */
int len() const {
return l;
}
void setlen(int newLen) {
l = newLen;
}
- /** @return size of the buffer */
- int getSize() const {
+
+ /** Returns the capacity of the buffer */
+ int capacity() const {
return size;
}
diff --git a/src/mongo/db/index/index_build_interceptor.cpp b/src/mongo/db/index/index_build_interceptor.cpp
index d1c2e0d6b5d..5e5568dc6c8 100644
--- a/src/mongo/db/index/index_build_interceptor.cpp
+++ b/src/mongo/db/index/index_build_interceptor.cpp
@@ -406,7 +406,7 @@ Status IndexBuildInterceptor::sideWrite(OperationContext* opCtx,
// from getBuffer().
builder.reset();
keyString.serialize(builder);
- BSONBinData binData(builder.buf(), builder.getSize(), BinDataGeneral);
+ BSONBinData binData(builder.buf(), builder.len(), BinDataGeneral);
toInsert.emplace_back(BSON("op" << (op == Op::kInsert ? "i" : "d") << "key" << binData));
}
@@ -417,7 +417,7 @@ Status IndexBuildInterceptor::sideWrite(OperationContext* opCtx,
for (const auto& keyString : multikeyMetadataKeys) {
builder.reset();
keyString.serialize(builder);
- BSONBinData binData(builder.buf(), builder.getSize(), BinDataGeneral);
+ BSONBinData binData(builder.buf(), builder.len(), BinDataGeneral);
toInsert.emplace_back(BSON("op"
<< "i"
<< "key" << binData));