From 0889c5fdd31312535a5ab33399e2fd0218c1e4cb Mon Sep 17 00:00:00 2001 From: "vladimir@pobox.com" Date: Mon, 25 Jun 2007 09:24:19 -0700 Subject: [PATCH] b=385584, crash with toDataURL on large canvas, r=stuart --- .../canvas/src/nsCanvasRenderingContext2D.cpp | 16 +++++++++++----- content/html/content/src/nsHTMLCanvasElement.cpp | 10 ++++++++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/content/canvas/src/nsCanvasRenderingContext2D.cpp b/content/canvas/src/nsCanvasRenderingContext2D.cpp index b423d197b6d5..57c5704fd4dd 100644 --- a/content/canvas/src/nsCanvasRenderingContext2D.cpp +++ b/content/canvas/src/nsCanvasRenderingContext2D.cpp @@ -720,6 +720,14 @@ nsCanvasRenderingContext2D::Render(nsIRenderingContext *rc) { nsresult rv = NS_OK; + if (!mSurface || !mCairo || + cairo_surface_status(mSurface) != CAIRO_STATUS_SUCCESS || + cairo_status(mCairo) != CAIRO_STATUS_SUCCESS) + return NS_ERROR_FAILURE; + + if (!mThebesSurface) + return NS_ERROR_FAILURE; + gfxContext* ctx = (gfxContext*) rc->GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT); nsRefPtr pat = new gfxPattern(mThebesSurface); @@ -748,14 +756,12 @@ nsCanvasRenderingContext2D::GetInputStream(const nsACString& aMimeType, const nsAString& aEncoderOptions, nsIInputStream **aStream) { + if (!mSurface || cairo_surface_status(mSurface) != CAIRO_STATUS_SUCCESS) + return NS_ERROR_FAILURE; + nsCString conid(NS_LITERAL_CSTRING("@mozilla.org/image/encoder;2?type=")); conid += aMimeType; - if (cairo_status(mCairo)) { - fprintf (stderr, "Cairo error! %d %s\n", cairo_status(mCairo), cairo_status_to_string(cairo_status(mCairo))); - fflush (stderr); - } - nsCOMPtr encoder = do_CreateInstance(conid.get()); if (!encoder) return NS_ERROR_FAILURE; diff --git a/content/html/content/src/nsHTMLCanvasElement.cpp b/content/html/content/src/nsHTMLCanvasElement.cpp index 54ee6032acdf..e1e870d7223a 100644 --- a/content/html/content/src/nsHTMLCanvasElement.cpp +++ b/content/html/content/src/nsHTMLCanvasElement.cpp @@ -455,10 +455,16 @@ nsHTMLCanvasElement::GetContext(const nsAString& aContextId, return NS_ERROR_INVALID_ARG; rv = mCurrentContext->SetCanvasElement(this); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_FAILED(rv)) { + mCurrentContext = nsnull; + return rv; + } rv = UpdateContext(); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_FAILED(rv)) { + mCurrentContext = nsnull; + return rv; + } mCurrentContextId.Assign(aContextId); } else if (!mCurrentContextId.Equals(aContextId)) {