From 9ff59dcd119937ba6a15cd97f55164265cbaa359 Mon Sep 17 00:00:00 2001 From: Seth Fowler Date: Wed, 22 May 2013 15:33:08 +0800 Subject: [PATCH] Bug 873455 - Add assertions for imgFrame::Init failure. r=joe --- image/src/RasterImage.cpp | 4 ++++ image/src/imgFrame.cpp | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/image/src/RasterImage.cpp b/image/src/RasterImage.cpp index db8a8594dd9..c604fbf5f84 100644 --- a/image/src/RasterImage.cpp +++ b/image/src/RasterImage.cpp @@ -1257,6 +1257,10 @@ RasterImage::InternalAddFrame(uint32_t framenum, nsAutoPtr frame(new imgFrame()); nsresult rv = frame->Init(aX, aY, aWidth, aHeight, aFormat, aPaletteDepth); + if (!(mSize.width > 0 && mSize.height > 0)) + NS_WARNING("Shouldn't call InternalAddFrame with zero size"); + if (!NS_SUCCEEDED(rv)) + NS_WARNING("imgFrame::Init should succeed"); NS_ENSURE_SUCCESS(rv, rv); // We know we are in a decoder. Therefore, we must unlock the previous frame diff --git a/image/src/imgFrame.cpp b/image/src/imgFrame.cpp index 003d89486ca..efba98bc34a 100644 --- a/image/src/imgFrame.cpp +++ b/image/src/imgFrame.cpp @@ -150,8 +150,10 @@ nsresult imgFrame::Init(int32_t aX, int32_t aY, int32_t aWidth, int32_t aHeight, gfxASurface::gfxImageFormat aFormat, uint8_t aPaletteDepth /* = 0 */) { // assert for properties that should be verified by decoders, warn for properties related to bad content - if (!AllowedImageSize(aWidth, aHeight)) + if (!AllowedImageSize(aWidth, aHeight)) { + NS_WARNING("Should have legal image size"); return NS_ERROR_FAILURE; + } mOffset.MoveTo(aX, aY); mSize.SizeTo(aWidth, aHeight); @@ -162,12 +164,15 @@ nsresult imgFrame::Init(int32_t aX, int32_t aY, int32_t aWidth, int32_t aHeight, if (aPaletteDepth != 0) { // We're creating for a paletted image. if (aPaletteDepth > 8) { + NS_WARNING("Should have legal palette depth"); NS_ERROR("This Depth is not supported"); return NS_ERROR_FAILURE; } // Use the fallible allocator here mPalettedImageData = (uint8_t*)moz_malloc(PaletteDataLength() + GetImageDataLength()); + if (!mPalettedImageData) + NS_WARNING("moz_malloc for paletted image data should succeed"); NS_ENSURE_TRUE(mPalettedImageData, NS_ERROR_OUT_OF_MEMORY); } else { // For Windows, we must create the device surface first (if we're @@ -195,6 +200,10 @@ nsresult imgFrame::Init(int32_t aX, int32_t aY, int32_t aWidth, int32_t aHeight, if (!mImageSurface || mImageSurface->CairoStatus()) { mImageSurface = nullptr; // guess + if (!mImageSurface) + NS_WARNING("Allocation of gfxImageSurface should succeed"); + if (!mImageSurface->CairoStatus()) + NS_WARNING("gfxImageSurface should have good CairoStatus"); return NS_ERROR_OUT_OF_MEMORY; }