Bug 1427091 - BlobSet must propagate the OOM error when appending a big string, r=smaug a=gchang
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 03 Jan 2018 22:49:36 +0100
changeset 445569 d5b2854b166bd6ef57ea3b4a46dd4bb70ba6e2ab
parent 445568 aca965dcf4386ed4bf92f5ac7da70f9d8fa84907
child 445570 528b663208430bef8ad584debf95771060ff0409
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, gchang
bugs1427091
milestone58.0
Bug 1427091 - BlobSet must propagate the OOM error when appending a big string, r=smaug a=gchang * * * Bug 1427091 - BlobSet must use nsCString instead of nsAutoCString, r=me
dom/file/BlobSet.cpp
--- a/dom/file/BlobSet.cpp
+++ b/dom/file/BlobSet.cpp
@@ -32,17 +32,20 @@ BlobSet::AppendVoidPtr(const void* aData
   mBlobImpls.AppendElement(blobImpl);
 
   return NS_OK;
 }
 
 nsresult
 BlobSet::AppendString(const nsAString& aString, bool nativeEOL)
 {
-  nsCString utf8Str = NS_ConvertUTF16toUTF8(aString);
+  nsCString utf8Str;
+  if (NS_WARN_IF(!AppendUTF16toUTF8(aString, utf8Str, mozilla::fallible))) {
+    return NS_ERROR_OUT_OF_MEMORY;
+  }
 
   if (nativeEOL) {
     if (utf8Str.Contains('\r')) {
       utf8Str.ReplaceSubstring("\r\n", "\n");
       utf8Str.ReplaceSubstring("\r", "\n");
     }
 #ifdef XP_WIN
     utf8Str.ReplaceSubstring("\n", "\r\n");