Bug 1455964: Make encodeBlob fallible on OOM. r?aswan
MozReview-Commit-ID: 83t9c9we5zg
--- 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