Bug 1337829 - ImageOps:DecodeToSurface may assert on a complete Sourcebuffer if ImageLib was not initialized. r=tnikkel
authorMarco Bonardo <mbonardo@mozilla.com>
Fri, 24 Feb 2017 16:38:24 +0100
changeset 382570 dd7207e80b803095d868985743134498d512f776
parent 382569 03be1ce804a5c457dfef4895daa4397f1fe40d02
child 382573 b780bfdac971fcba73575f454a45d042cf2ed14e
push idunknown
push userunknown
push dateunknown
reviewerstnikkel
bugs1337829
milestone54.0a1
Bug 1337829 - ImageOps:DecodeToSurface may assert on a complete Sourcebuffer if ImageLib was not initialized. r=tnikkel MozReview-Commit-ID: 5GBMnretTbS
image/ImageOps.cpp
--- a/image/ImageOps.cpp
+++ b/image/ImageOps.cpp
@@ -109,19 +109,23 @@ ImageOps::DecodeToSurface(nsIInputStream
   // Write the data into a SourceBuffer.
   NotNull<RefPtr<SourceBuffer>> sourceBuffer = WrapNotNull(new SourceBuffer());
   sourceBuffer->ExpectLength(length);
   rv = sourceBuffer->AppendFromInputStream(inputStream, length);
   if (NS_FAILED(rv)) {
     return nullptr;
   }
   // Make sure our sourceBuffer is marked as complete.
-  if (!sourceBuffer->IsComplete()) {
-    sourceBuffer->Complete(NS_OK);
+  if (sourceBuffer->IsComplete()) {
+    NS_WARNING("The SourceBuffer was unexpectedly marked as complete. This may "
+               "indicate either an OOM condition, or that imagelib was not "
+               "initialized properly.");
+    return nullptr;
   }
+  sourceBuffer->Complete(NS_OK);
 
   // Create a decoder.
   DecoderType decoderType =
     DecoderFactory::GetDecoderType(PromiseFlatCString(aMimeType).get());
   RefPtr<Decoder> decoder =
     DecoderFactory::CreateAnonymousDecoder(decoderType, sourceBuffer,
                                            Nothing(), ToSurfaceFlags(aFlags));
   if (!decoder) {