Skip to content

Commit f0f0779

Browse files
benetyEvergreen Agent
authored andcommitted
SERVER-50328 fix use-after-free error with corruptDocumentOnInsert fail point
1 parent f37ab82 commit f0f0779

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/mongo/db/catalog/collection_impl.cpp

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

641641
if (MONGO_unlikely(corruptDocumentOnInsert.shouldFail())) {
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());
645-
646-
records.emplace_back(Record{RecordId(), RecordData(&copyBuffer[0], copyBuffer.size())});
642+
// Insert a truncated record that is half the expected size of the source document.
643+
records.emplace_back(Record{RecordId(), RecordData(doc.objdata(), doc.objsize() / 2)});
647644
timestamps.emplace_back(it->oplogSlot.getTimestamp());
648645
continue;
649646
}

0 commit comments

Comments
 (0)