зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1758643 - Check for maximum string length before outputting profile JSON - r=florian
The promise to be resolved may end up in JavaScript, so we check for the maximum JS string length -- which is under the nsCString max length, so we won't fail the too-big-string assertion there. Differential Revision: https://phabricator.services.mozilla.com/D152024
This commit is contained in:
Родитель
83311bbbd6
Коммит
2eb04e7cbc
|
@ -46,6 +46,8 @@ using dom::AutoJSAPI;
|
|||
using dom::Promise;
|
||||
using std::string;
|
||||
|
||||
static constexpr size_t scLengthMax = size_t(JS::MaxStringLength);
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsProfiler, nsIProfiler)
|
||||
|
||||
nsProfiler::nsProfiler() : mGathering(false) {}
|
||||
|
@ -1326,8 +1328,15 @@ void nsProfiler::FinishGathering() {
|
|||
// Close the root object of the generated JSON.
|
||||
mWriter->End();
|
||||
|
||||
// And try to resolve the promise with the profile JSON.
|
||||
const size_t len = mWriter->ChunkedWriteFunc().Length();
|
||||
if (len >= scLengthMax) {
|
||||
NS_WARNING("Profile JSON is too big to fit in a string.");
|
||||
ResetGathering(NS_ERROR_FILE_TOO_BIG);
|
||||
return;
|
||||
}
|
||||
|
||||
UniquePtr<char[]> buf = mWriter->ChunkedWriteFunc().CopyData();
|
||||
size_t len = strlen(buf.get());
|
||||
nsCString result;
|
||||
result.Adopt(buf.release(), len);
|
||||
mPromiseHolder->Resolve(std::move(result), __func__);
|
||||
|
|
Загрузка…
Ссылка в новой задаче