Skip to content

Commit e83be1d

Browse files
benetyEvergreen Agent
authored andcommitted
SERVER-50205 fix corruptDocumentOnInsert fail point
1 parent e0bbfe1 commit e83be1d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/mongo/db/catalog/collection_impl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -639,11 +639,11 @@ Status CollectionImpl::_insertDocuments(OperationContext* opCtx,
639639
const auto& doc = it->doc;
640640

641641
if (MONGO_unlikely(corruptDocumentOnInsert.shouldFail())) {
642-
std::string copyBuffer(doc.objdata(), doc.objsize());
643-
copyBuffer.data()[5] = char(0x90);
642+
// Generate a corrupted copy of 'obj' that is half the size of the source doc.
643+
std::vector<char> copyBuffer(doc.objsize() / 2);
644+
std::memcpy(&copyBuffer[0], doc.objdata(), copyBuffer.size());
644645

645-
records.emplace_back(
646-
Record{RecordId(), RecordData(copyBuffer.c_str(), copyBuffer.size())});
646+
records.emplace_back(Record{RecordId(), RecordData(&copyBuffer[0], copyBuffer.size())});
647647
timestamps.emplace_back(it->oplogSlot.getTimestamp());
648648
continue;
649649
}

0 commit comments

Comments
 (0)