Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Unified Diff: src/effects/gradients/Sk4fGradientBase.cpp

Issue 2474463002: Fix GradientShaderBase4fContext::Interval fuzzer assert (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/effects/gradients/Sk4fGradientBase.cpp
diff --git a/src/effects/gradients/Sk4fGradientBase.cpp b/src/effects/gradients/Sk4fGradientBase.cpp
index 5cabab967a56c78b80b1a51478df215541cbaed9..8ecac30b334c3f58b26560393f1a63fb4f0ece40 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);
+ }
});
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698