aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/effects
diff options
context:
space:
mode:
authorGravatar Florin Malita <fmalita@chromium.org>2017-04-18 13:47:15 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-04-19 17:33:08 +0000
commit03013084aac29967ee0559efce817b39234f4aa6 (patch)
treeae9232cf9ab36cbd548060cfe323af15a68a7aab /src/effects
parenta4432dd418ca9ea31938ad645b1b231340bc29da (diff)
Fix SkATan2_255 fuzzer crash
Test for degenerate values after computing the ratio, instead of attempting to catch all tricky cases upfront. BUG=skia:6511 Change-Id: I8e3421675994dd68a1eff1af3f1456917dd1f9e1 Reviewed-on: https://skia-review.googlesource.com/13726 Reviewed-by: Herb Derby <herb@google.com> Commit-Queue: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'src/effects')
-rw-r--r--src/effects/gradients/SkSweepGradient.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/effects/gradients/SkSweepGradient.cpp b/src/effects/gradients/SkSweepGradient.cpp
index 27517bb080..23f77b3ab4 100644
--- a/src/effects/gradients/SkSweepGradient.cpp
+++ b/src/effects/gradients/SkSweepGradient.cpp
@@ -9,6 +9,7 @@
#include "SkSweepGradient.h"
#include <algorithm>
+#include <cmath>
static SkMatrix translate(SkScalar dx, SkScalar dy) {
SkMatrix matrix;
@@ -80,12 +81,16 @@ static unsigned SkATan2_255(float y, float x) {
}
#else
static unsigned SkATan2_255(float y, float x) {
- if (y == 0 && x == 0) return 0;
float yabs = sk_float_abs(y),
- xabs = sk_float_abs(x);
+ xabs = sk_float_abs(x);
float little, big;
std::tie(little, big) = std::minmax(yabs, xabs);
float a = little/big;
+ if (!std::isfinite(a)) {
+ return 0;
+ }
+ SkASSERT(a >=0 && a <= 1);
+
float s = a * a;
float r = a*(40.57589784014689f
+ s*(-13.222755844396332f + s*(6.314046289038564f - s*1.7989502668982151f)));