From d7b4ab4573b4c9f755a4b2cf3f294f529550252a Mon Sep 17 00:00:00 2001 From: Kyle Huey Date: Thu, 10 Mar 2016 01:50:56 -0800 Subject: [PATCH] Bug 1253059: Use fallible allocation in the worker error reporter. r=baku --- dom/workers/WorkerPrivate.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index 4126919f15ba..e8f0610e9694 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -5795,7 +5795,13 @@ WorkerPrivate::ReportError(JSContext* aCx, const char* aFallbackMessage, } if (message.IsEmpty()) { - message = NS_ConvertUTF8toUTF16(aFallbackMessage); + nsDependentCString fallbackMessage(aFallbackMessage); + if (!AppendUTF8toUTF16(fallbackMessage, message, mozilla::fallible)) { + // Try again, with only a 1 KB string. Do this infallibly this time. + // If the user doesn't have 1 KB to spare we're done anyways. + nsDependentCString truncatedFallbackMessage(aFallbackMessage, 1024); + AppendUTF8toUTF16(truncatedFallbackMessage, message); + } } mErrorHandlerRecursionCount++;