Bug 1455964 - Make encodeBlob fallible on OOM. r=zombie, a=jcristau
authorKris Maglione <maglione.k@gmail.com>
Sun, 22 Apr 2018 12:20:20 -0700
changeset 802270 9a546537d8bff630a1fbf876be55f9d599972955
parent 802269 4a61437c8f0ad49cb93543a4f6ed7ddf12c0244a
child 802271 1b10610a4e89c4b138da6d3d8084ded81dad493e
push id111850
push userbmo:tom@mozilla.com
push dateThu, 31 May 2018 16:41:37 +0000
reviewerszombie, jcristau
bugs1455964
milestone60.0.2
Bug 1455964 - Make encodeBlob fallible on OOM. r=zombie, a=jcristau MozReview-Commit-ID: 83t9c9we5zg
toolkit/mozapps/extensions/AddonManagerStartup.cpp
--- a/toolkit/mozapps/extensions/AddonManagerStartup.cpp
+++ b/toolkit/mozapps/extensions/AddonManagerStartup.cpp
@@ -141,28 +141,34 @@ EncodeLZ4(const nsACString& data, const 
 {
   // Note: We want to include the null terminator here.
   nsDependentCSubstring magic(magicNumber, sizeof(magicNumber));
 
   nsAutoCString result;
   result.Append(magic);
 
   auto off = result.Length();
-  result.SetLength(off + 4);
+  if (!result.SetLength(off + 4, fallible)) {
+    return Err(NS_ERROR_OUT_OF_MEMORY);
+  }
 
   LittleEndian::writeUint32(result.BeginWriting() + off, data.Length());
   off += 4;
 
   auto size = LZ4::maxCompressedSize(data.Length());
-  result.SetLength(off + size);
+  if (!result.SetLength(off + size, fallible)) {
+    return Err(NS_ERROR_OUT_OF_MEMORY);
+  }
 
   size = LZ4::compress(data.BeginReading(), data.Length(),
                        result.BeginWriting() + off);
 
-  result.SetLength(off + size);
+  if (!result.SetLength(off + size, fallible)) {
+    return Err(NS_ERROR_OUT_OF_MEMORY);
+  }
   return result;
 }
 
 static_assert(sizeof STRUCTURED_CLONE_MAGIC % 8 == 0,
               "Magic number should be an array of uint64_t");
 
 /**
  * Reads the contents of a LZ4-compressed file, as stored by the OS.File