summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLouis Williams <louis.williams@mongodb.com>2021-06-17 10:41:48 -0400
committerLouis Williams <louis.williams@mongodb.com>2021-06-23 10:44:21 -0400
commitbaa350cb285592702833f4f51ecc7ffbb5982080 (patch)
tree0d5d01860a8a87f3bd4bacb3fd10125306045ca6
parentefaea9a3abb72c1fe899a9a0926a19813b044f5f (diff)
downloadmongo-baa350cb285592702833f4f51ecc7ffbb5982080.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)
-rw-r--r--src/mongo/bson/bsonobjbuilder.h2
-rw-r--r--src/mongo/bson/util/builder.h6
-rw-r--r--src/mongo/db/index/index_build_interceptor.cpp4
3 files changed, 6 insertions, 6 deletions
diff --git a/src/mongo/bson/bsonobjbuilder.h b/src/mongo/bson/bsonobjbuilder.h
index a7860a45588..4dad20d270d 100644
--- a/src/mongo/bson/bsonobjbuilder.h
+++ b/src/mongo/bson/bsonobjbuilder.h
@@ -663,7 +663,7 @@ protected:
// 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.
- return !_doneCalled && _b.buf() && _buf.getSize() == 0;
+ return !_doneCalled && _b.buf() && _buf.capacity() == 0;
}
// Must be called by derived class destructors.
diff --git a/src/mongo/bson/util/builder.h b/src/mongo/bson/util/builder.h
index ad0286afde7..70daf863547 100644
--- a/src/mongo/bson/util/builder.h
+++ b/src/mongo/bson/util/builder.h
@@ -387,15 +387,15 @@ 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 _buf.capacity();
}
diff --git a/src/mongo/db/index/index_build_interceptor.cpp b/src/mongo/db/index/index_build_interceptor.cpp
index 835441e7109..77d13478b30 100644
--- a/src/mongo/db/index/index_build_interceptor.cpp
+++ b/src/mongo/db/index/index_build_interceptor.cpp
@@ -483,7 +483,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));
}
@@ -494,7 +494,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));