From 5b1a7c21006175d313aad09ef40f9453a21480e2 Mon Sep 17 00:00:00 2001 From: Florin Malita Date: Sun, 20 Nov 2016 19:10:59 -0500 Subject: Fuzzer assert in GradientShaderBase4fContext::TSampler Similar to https://codereview.chromium.org/2472763002, we also need to clamp the tiled value in kRepeat mode, to avoid snapping to 1.0f. R=reed@google.com,herb@google.com BUG=skia:5975 GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=5079 Change-Id: I8fdac36c0d112d5eb76e47c3e4156a79a4d13b36 Reviewed-on: https://skia-review.googlesource.com/5079 Reviewed-by: Herb Derby Commit-Queue: Florin Malita --- src/effects/gradients/Sk4fGradientBase.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'src/effects/gradients/Sk4fGradientBase.cpp') diff --git a/src/effects/gradients/Sk4fGradientBase.cpp b/src/effects/gradients/Sk4fGradientBase.cpp index 0c54ba27bf..91f418564f 100644 --- a/src/effects/gradients/Sk4fGradientBase.cpp +++ b/src/effects/gradients/Sk4fGradientBase.cpp @@ -337,9 +337,19 @@ public: TSampler(const GradientShaderBase4fContext& ctx) : fFirstInterval(ctx.fIntervals.begin()) , fLastInterval(ctx.fIntervals.end() - 1) - , fInterval(nullptr) - , fLargestLessThanTwo(nextafterf(2, 0)) { + , fInterval(nullptr) { SkASSERT(fLastInterval >= fFirstInterval); + switch (tileMode) { + case kClamp_TileMode: + fLargestIntervalValue = SK_ScalarInfinity; + break; + case kRepeat_TileMode: + fLargestIntervalValue = nextafterf(1, 0); + break; + case kMirror_TileMode: + fLargestIntervalValue = nextafterf(2.0f, 0); + break; + } } Sk4f sample(SkScalar t) { @@ -368,11 +378,12 @@ private: return t; case kRepeat_TileMode: // t % 1 (intervals range: [0..1)) - return t - SkScalarFloorToScalar(t); + // Due to the extra arithmetic, we must clamp to ensure the value remains less than 1. + return SkTMin(t - SkScalarFloorToScalar(t), fLargestIntervalValue); case kMirror_TileMode: // t % 2 (synthetic mirror intervals expand the range to [0..2) // Due to the extra arithmetic, we must clamp to ensure the value remains less than 2. - return SkTMin(t - SkScalarFloorToScalar(t / 2) * 2, fLargestLessThanTwo); + return SkTMin(t - SkScalarFloorToScalar(t / 2) * 2, fLargestIntervalValue); } SK_ABORT("Unhandled tile mode."); @@ -442,7 +453,7 @@ private: const Interval* fLastInterval; const Interval* fInterval; SkScalar fPrevT; - SkScalar fLargestLessThanTwo; + SkScalar fLargestIntervalValue; Sk4f fCc; Sk4f fDc; }; -- cgit v1.2.3