Bug 1545521: Use lz4_decompress_safe to decode add-on manager startup cache blobs. r=aswan
authorKris Maglione <maglione.k@gmail.com>
Thu, 18 Apr 2019 13:17:37 -0700
changeset 470354 41b4775f70f99f1cb4f4dd3e03a189a83faad578
parent 470353 a69337c09a3aaa55249bfb307d58192a1baae470
child 470355 d480aa70ccbfd2770b64828b92f8b83292f840a7
push id112867
push usermaglione.k@gmail.com
push dateMon, 22 Apr 2019 20:34:34 +0000
treeherdermozilla-inbound@b21620648d31 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1545521
milestone68.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 1545521: Use lz4_decompress_safe to decode add-on manager startup cache blobs. r=aswan In previous versions of the LZ4 library, lz4_decompress_fast, which does not take an input buffer size, was supposed to be faster than lz4_decompress_safe, which does. In newer versions, however, the reverse is supposed to be true, and lz4_decompress_fast is therefore deprecated. This patch updates our code to use the now-preferred "safe" version of the API. Differential Revision: https://phabricator.services.mozilla.com/D28128
toolkit/mozapps/extensions/AddonManagerStartup.cpp
--- a/toolkit/mozapps/extensions/AddonManagerStartup.cpp
+++ b/toolkit/mozapps/extensions/AddonManagerStartup.cpp
@@ -111,22 +111,28 @@ static Result<nsCString, nsresult> Decod
   if (lz4.Length() < HEADER_SIZE || StringHead(lz4, magic.Length()) != magic) {
     return Err(NS_ERROR_UNEXPECTED);
   }
 
   auto data = lz4.BeginReading() + magic.Length();
   auto size = LittleEndian::readUint32(data);
   data += 4;
 
+  size_t dataLen = lz4.EndReading() - data;
+  size_t outputSize;
+
   nsCString result;
   if (!result.SetLength(size, fallible) ||
-      !LZ4::decompress(data, result.BeginWriting(), size)) {
+      !LZ4::decompress(data, dataLen, result.BeginWriting(), size,
+                       &outputSize)) {
     return Err(NS_ERROR_UNEXPECTED);
   }
 
+  MOZ_DIAGNOSTIC_ASSERT(size == outputSize);
+
   return result;
 }
 
 // Our zlib headers redefine this to MOZ_Z_compress, which breaks LZ4::compress
 #undef compress
 
 template <typename T>
 static Result<nsCString, nsresult> EncodeLZ4(const nsACString& data,