Bug 1669943 - Avoid crashing content process when failing to allocate StructuredCloneReadInfoChild array. r=dom-workers-and-storage-reviewers,asuth

Differential Revision: https://phabricator.services.mozilla.com/D92897
This commit is contained in:
Simon Giesecke 2020-10-23 11:02:11 +00:00
Родитель 98ffa782b9
Коммит 35fa833449
1 изменённых файлов: 18 добавлений и 14 удалений

Просмотреть файл

@ -2440,22 +2440,26 @@ void BackgroundRequestChild::HandleResponse(
nsTArray<StructuredCloneReadInfoChild> cloneReadInfos;
if (!aResponse.IsEmpty()) {
const uint32_t count = aResponse.Length();
IDB_TRY(OkIf(cloneReadInfos.SetCapacity(aResponse.Length(), fallible)),
QM_VOID, ([&aResponse, this](const auto) {
// Since we are under memory pressure, release aResponse early.
aResponse.Clear();
cloneReadInfos.SetCapacity(count);
DispatchErrorEvent(mRequest, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR,
AcquireTransaction());
std::transform(
std::make_move_iterator(aResponse.begin()),
std::make_move_iterator(aResponse.end()),
MakeBackInserter(cloneReadInfos),
[database = mTransaction->Database(),
this](SerializedStructuredCloneReadInfo&& serializedCloneInfo) {
return DeserializeStructuredCloneReadInfo(
std::move(serializedCloneInfo), database,
[this] { return std::move(*GetNextCloneData()); });
});
}
MOZ_ASSERT(mTransaction->IsAborted());
}));
std::transform(std::make_move_iterator(aResponse.begin()),
std::make_move_iterator(aResponse.end()),
MakeBackInserter(cloneReadInfos),
[database = mTransaction->Database(), this](
SerializedStructuredCloneReadInfo&& serializedCloneInfo) {
return DeserializeStructuredCloneReadInfo(
std::move(serializedCloneInfo), database,
[this] { return std::move(*GetNextCloneData()); });
});
SetResultAndDispatchSuccessEvent(mRequest, AcquireTransaction(),
cloneReadInfos);