Bug 880842 - Guard against null temporary drawing surface r=mattwoodrow
authorJames Willcox <snorp@snorp.net>
Wed, 12 Jun 2013 09:03:52 -0400
changeset 146287 8203dff7f4fb6289f4766b02dd214df93ad74ffc
parent 146286 1f1742107151ddf9a5333a7e92952e3b801e1d8d
child 146288 58df50e6b861b8f23203486fc606930540a6de91
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs880842
milestone24.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 880842 - Guard against null temporary drawing surface r=mattwoodrow
content/canvas/src/CanvasRenderingContext2D.cpp
--- a/content/canvas/src/CanvasRenderingContext2D.cpp
+++ b/content/canvas/src/CanvasRenderingContext2D.cpp
@@ -3213,29 +3213,38 @@ CanvasRenderingContext2D::DrawWindow(nsI
   if (gfxPlatform::GetPlatform()->SupportsAzureContentForDrawTarget(mTarget)) {
     thebes = new gfxContext(mTarget);
     thebes->SetMatrix(gfxMatrix(matrix._11, matrix._12, matrix._21,
                                 matrix._22, matrix._31, matrix._32));
   } else {
     drawSurf =
       gfxPlatform::GetPlatform()->CreateOffscreenSurface(gfxIntSize(ceil(w), ceil(h)),
                                                          gfxASurface::CONTENT_COLOR_ALPHA);
+    if (!drawSurf) {
+      error.Throw(NS_ERROR_FAILURE);
+      return;
+    }
 
     drawSurf->SetDeviceOffset(gfxPoint(-floor(x), -floor(y)));
     thebes = new gfxContext(drawSurf);
     thebes->Translate(gfxPoint(floor(x), floor(y)));
   }
 
   nsCOMPtr<nsIPresShell> shell = presContext->PresShell();
   unused << shell->RenderDocument(r, renderDocFlags, backgroundColor, thebes);
   if (drawSurf) {
     gfxIntSize size = drawSurf->GetSize();
 
     drawSurf->SetDeviceOffset(gfxPoint(0, 0));
     nsRefPtr<gfxImageSurface> img = drawSurf->GetAsReadableARGB32ImageSurface();
+    if (!img || !img->Data()) {
+      error.Throw(NS_ERROR_FAILURE);
+      return;
+    }
+
     RefPtr<SourceSurface> data =
       mTarget->CreateSourceSurfaceFromData(img->Data(),
                                            IntSize(size.width, size.height),
                                            img->Stride(),
                                            FORMAT_B8G8R8A8);
     mgfx::Rect rect(0, 0, w, h);
     mTarget->DrawSurface(data, rect, rect);
     mTarget->Flush();