Bug 1455964: Make encodeBlob fallible on OOM. r=zombie
authorKris Maglione <maglione.k@gmail.com>
Sun, 22 Apr 2018 12:20:20 -0700
changeset 468939 5336e6fd895be772cf603dbd8a6580be723829aa
parent 468938 f21d1cfe5d07734767e217eeda91bab9d83f12d1
child 468940 6bf69d965bbe697e69fc0df014e7f326aa423385
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerszombie
bugs1455964
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1455964: Make encodeBlob fallible on OOM. r=zombie MozReview-Commit-ID: 83t9c9we5zg
toolkit/mozapps/extensions/AddonManagerStartup.cpp
--- a/toolkit/mozapps/extensions/AddonManagerStartup.cpp
+++ b/toolkit/mozapps/extensions/AddonManagerStartup.cpp
@@ -140,28 +140,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