Bug 1309117 - Make ImgFromData fallible. r=masayuki
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Tue, 11 Oct 2016 19:28:30 +0900
changeset 348436 2321811e03543dd5c492d560375db13f3290210e
parent 348435 18255363130ed9dc207ce493b6eaf799156f3211
child 348437 a6dd1257f5357fe863f23eb676e4c921827c0f94
push id13
push userfmarier@mozilla.com
push dateFri, 11 Nov 2016 01:36:56 +0000
reviewersmasayuki
bugs1309117
milestone52.0a1
Bug 1309117 - Make ImgFromData fallible. r=masayuki When pasting large image, it may cause OOM when generating base64 data. So we should use fallible allocator instead. Also, base64 is ASCII, so we should use AppendASCIItoUTF16 instead of AppendUTF8toUTF16. MozReview-Commit-ID: 8yWPxfEcEwv
editor/libeditor/HTMLEditorDataTransfer.cpp
--- a/editor/libeditor/HTMLEditorDataTransfer.cpp
+++ b/editor/libeditor/HTMLEditorDataTransfer.cpp
@@ -1020,17 +1020,19 @@ ImgFromData(const nsACString& aType, con
 {
   nsAutoCString data64;
   nsresult rv = Base64Encode(aData, data64);
   NS_ENSURE_SUCCESS(rv, rv);
 
   aOutput.AssignLiteral("<IMG src=\"data:");
   AppendUTF8toUTF16(aType, aOutput);
   aOutput.AppendLiteral(";base64,");
-  AppendUTF8toUTF16(data64, aOutput);
+  if (!AppendASCIItoUTF16(data64, aOutput, fallible_t())) {
+    return NS_ERROR_OUT_OF_MEMORY;
+  }
   aOutput.AppendLiteral("\" alt=\"\" >");
   return NS_OK;
 }
 
 NS_IMPL_ISUPPORTS(HTMLEditor::BlobReader, nsIEditorBlobListener)
 
 HTMLEditor::BlobReader::BlobReader(BlobImpl* aBlob,
                                    HTMLEditor* aHTMLEditor,