Bug 1362194 - Part 2: Make Base64Decode tolerant of allocation failures. r=mccr8, a=gchang
☠☠ backed out by e6d59d3fce9c ☠ ☠
authorNathan Froyd <froydnj@mozilla.com>
Fri, 05 May 2017 11:33:36 -0400
changeset 396227 cb4ac444390794347fa89c101c8743196bf33824
parent 396226 6d27074d2779a928f29407042dc553cccfd43118
child 396228 07849fe5dfd8fb01c1d8c9335b3dd6623b065061
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8, gchang
bugs1362194
milestone54.0
Bug 1362194 - Part 2: Make Base64Decode tolerant of allocation failures. r=mccr8, a=gchang We need to use a fallible CopyASCIItoUTF16 function, since we might not have enough memory to perform the copy.
xpcom/io/Base64.cpp
--- a/xpcom/io/Base64.cpp
+++ b/xpcom/io/Base64.cpp
@@ -464,18 +464,22 @@ Base64Decode(const nsACString& aBase64, 
 nsresult
 Base64Decode(const nsAString& aBase64, nsAString& aBinary)
 {
   NS_LossyConvertUTF16toASCII base64(aBase64);
   nsAutoCString binary;
 
   nsresult rv = Base64Decode(base64, binary);
   if (NS_SUCCEEDED(rv)) {
-    CopyASCIItoUTF16(binary, aBinary);
-  } else {
+    if (!CopyASCIItoUTF16(binary, aBinary, mozilla::fallible)) {
+      rv = NS_ERROR_OUT_OF_MEMORY;
+    }
+  }
+
+  if (NS_FAILED(rv)) {
     aBinary.Truncate();
   }
 
   return rv;
 }
 
 nsresult
 Base64URLDecode(const nsACString& aBase64,