From cc34176c040c9703e351af7268dfc3a8b3cbf71d Mon Sep 17 00:00:00 2001 From: fmalita Date: Wed, 2 Nov 2016 13:10:51 -0700 Subject: [PATCH] Fix GradientShaderBase4fContext::Interval fuzzer assert Although the iterator ensures v0 != v1, 2 - v0 may still be equal to 2 - v1 for very small values due to limited float precision. We need to recheck the inequality to avoid triggering Interval asserts. BUG=skia:5903 R=reed@google.com GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2474463002 Review-Url: https://codereview.chromium.org/2474463002 --- src/effects/gradients/Sk4fGradientBase.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/effects/gradients/Sk4fGradientBase.cpp b/src/effects/gradients/Sk4fGradientBase.cpp index 5cabab967a..8ecac30b33 100644 --- a/src/effects/gradients/Sk4fGradientBase.cpp +++ b/src/effects/gradients/Sk4fGradientBase.cpp @@ -125,7 +125,6 @@ Interval::Interval(const Sk4f& c0, SkScalar p0, : fP0(p0) , fP1(p1) , fZeroRamp((c0 == c1).allTrue()) { - SkASSERT(p0 != p1); // Either p0 or p1 can be (-)inf for synthetic clamp edge intervals. SkASSERT(SkScalarIsFinite(p0) || SkScalarIsFinite(p1)); @@ -274,10 +273,16 @@ GradientShaderBase4fContext::addMirrorIntervals(const SkGradientShaderBase& shad iter.iterate([this, &componentScale] (SkColor c0, SkColor c1, SkScalar p0, SkScalar p1) { SkASSERT(fIntervals.empty() || fIntervals.back().fP1 == 2 - p0); - fIntervals.emplace_back(pack_color(c0, fColorsArePremul, componentScale), - 2 - p0, - pack_color(c1, fColorsArePremul, componentScale), - 2 - p1); + const auto mirror_p0 = 2 - p0; + const auto mirror_p1 = 2 - p1; + // mirror_p1 & mirror_p1 may collapse for very small values - recheck to avoid + // triggering Interval asserts. + if (mirror_p0 != mirror_p1) { + fIntervals.emplace_back(pack_color(c0, fColorsArePremul, componentScale), + mirror_p0, + pack_color(c1, fColorsArePremul, componentScale), + mirror_p1); + } }); }