Bug 1351015 - Not assuming nsStyleImage::ComputeActualCropRect always return true. r=heycam

nsStyleImage::ComputeActualCropRect may return false under 4 conditions
1. mType is not eStyleImageType_Image.
   This function is design to be used when mType is eStyleImageType_Image.
   Replace this 'if' check by MOZ_ASSERT.
2. nsStyleImage::GetImageData() returns nullptr
   This function will return true if this image refers to a local-ref resource.
3. GetImage returns failure or does not return a valid imgIContainer.
   It's possible. Please refers to the comment in imgReqestProxy::GetImage
   at [1].
4. imageSize is empty
   It's possible too. By giving a malformed image to a style image, we will hit
   this condition. And this is right what we met in this bug.

Since ComputeActualCropRect may actaully return false, we should remove the
NS_ASSERTION that assume it will always return true.

[1]
https://hg.mozilla.org/mozilla-central/file/7f1f1559cd8d/image/imgRequestProxy.cpp#l513

MozReview-Commit-ID: KHTFQJjiLtT
This commit is contained in:
cku
2017-04-22 03:28:20 +08:00
parent 8a3a8e60ed
commit 4ac7347cd4
4 changed files with 6 additions and 9 deletions

View File

@@ -148,7 +148,6 @@ nsImageRenderer::PrepareImage()
bool isEntireImage;
bool success =
mImage->ComputeActualCropRect(actualCropRect, &isEntireImage);
NS_ASSERTION(success, "ComputeActualCropRect() should not fail here");
if (!success || actualCropRect.IsEmpty()) {
// The cropped image has zero size
mPrepareResult = DrawResult::BAD_IMAGE;

View File

@@ -4,7 +4,7 @@
== background-common-usage-pixel.html background-common-usage-pixel.html
== background-draw-nothing-empty-rect.html background-draw-nothing-empty-rect.html
== background-draw-nothing-invalid-syntax.html background-draw-nothing-invalid-syntax.html
asserts(0-8) == background-draw-nothing-malformed-images.html background-draw-nothing-malformed-images.html
== background-draw-nothing-malformed-images.html background-draw-nothing-malformed-images.html
== background-monster-rect.html background-monster-rect.html
== background-over-size-rect.html background-over-size-rect.html
fails == background-test-parser.html background-test-parser.html

View File

@@ -3,7 +3,7 @@
== background-common-usage-pixel.html background-common-usage-ref.html
== background-draw-nothing-empty-rect.html background-draw-nothing-ref.html
== background-draw-nothing-invalid-syntax.html background-draw-nothing-ref.html
asserts(0-6) == background-draw-nothing-malformed-images.html background-draw-nothing-ref.html # Bug 576419
== background-draw-nothing-malformed-images.html background-draw-nothing-ref.html
== background-monster-rect.html background-monster-rect-ref.html
== background-over-size-rect.html background-over-size-rect-ref.html
== background-test-parser.html background-test-parser-ref.html

View File

@@ -2338,9 +2338,9 @@ bool
nsStyleImage::ComputeActualCropRect(nsIntRect& aActualCropRect,
bool* aIsEntireImage) const
{
if (mType != eStyleImageType_Image) {
return false;
}
MOZ_ASSERT(mType == eStyleImageType_Image,
"This function is designed to be used only when mType"
"is eStyleImageType_Image.");
imgRequestProxy* req = GetImageData();
if (!req) {
@@ -2421,9 +2421,7 @@ nsStyleImage::IsOpaque() const
// Must make sure if mCropRect contains at least a pixel.
// XXX Is this optimization worth it? Maybe I should just return false.
nsIntRect actualCropRect;
bool rv = ComputeActualCropRect(actualCropRect);
NS_ASSERTION(rv, "ComputeActualCropRect() can not fail here");
return rv && !actualCropRect.IsEmpty();
return ComputeActualCropRect(actualCropRect) && !actualCropRect.IsEmpty();
}
return false;