Bug 1069584: Bail if a cairo surface is in an invalid state. r=jrmuizel
authorBas Schouten <bschouten@mozilla.com>
Fri, 19 Sep 2014 00:01:24 +0200
changeset 732 844ded49a315f7e37f5ed873858f8ad5828d3aea
parent 731 38f6c062f17979be9ba3e449b23946a937ee1c65
child 733 d0d0ba810490c12a4dd7911428515fabf3fa1b28
push id274
push userbschouten@mozilla.com
push dateTue, 23 Sep 2014 16:10:56 +0000
reviewersjrmuizel
bugs1069584
Bug 1069584: Bail if a cairo surface is in an invalid state. r=jrmuizel
DrawTargetCairo.cpp
--- a/DrawTargetCairo.cpp
+++ b/DrawTargetCairo.cpp
@@ -1383,16 +1383,23 @@ DrawTargetCairo::CreateSimilarDrawTarget
   gfxCriticalError() << "Failed to create similar cairo surface! Size: " << aSize << " Status: " << cairo_surface_status(similar);
 
   return nullptr;
 }
 
 bool
 DrawTargetCairo::InitAlreadyReferenced(cairo_surface_t* aSurface, const IntSize& aSize, SurfaceFormat* aFormat)
 {
+  if (cairo_surface_status(aSurface)) {
+    gfxCriticalError() << "Attempt to create DrawTarget for invalid surface. "
+                       << aSize << " Cairo Status: " << cairo_surface_status(aSurface);
+    cairo_surface_destroy(aSurface);
+    return false;
+  }
+
   mContext = cairo_create(aSurface);
   mSurface = aSurface;
   mSize = aSize;
   mFormat = aFormat ? *aFormat : CairoContentToGfxFormat(cairo_surface_get_content(aSurface));
 
   // Cairo image surface have a bug where they will allocate a mask surface (for clipping)
   // the size of the clip extents, and don't take the surface extents into account.
   // Add a manual clip to the surface extents to prevent this.