aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar caryclark <caryclark@google.com>2016-05-27 05:24:37 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-05-27 05:24:38 -0700
commit93ca884879e3469b46d32c36deb7b46f2fff1c0c (patch)
treed35e1eeb53f323ffca11054db7e3180fc2fe19e1 /src
parent64022c1ed2174fb499027f902c25be60ef7c3737 (diff)
pin before calling acos
Adobe reports some user crashes in acos(). While the cause is unknown, it's safe and may help stability to pin the input in case the arguments drifted slightly outside [-1, 1]. R=reed@google.com BUG=skia:5222 GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2006653006 Review-Url: https://codereview.chromium.org/2006653006
Diffstat (limited to 'src')
-rw-r--r--src/core/SkGeometry.cpp3
-rw-r--r--src/pathops/SkPathOpsCubic.cpp3
2 files changed, 4 insertions, 2 deletions
diff --git a/src/core/SkGeometry.cpp b/src/core/SkGeometry.cpp
index 7256b9e517..5d181a3a20 100644
--- a/src/core/SkGeometry.cpp
+++ b/src/core/SkGeometry.cpp
@@ -743,7 +743,8 @@ static int solve_cubic_poly(const SkScalar coeff[4], SkScalar tValues[3]) {
SkScalar r;
if (R2MinusQ3 < 0) { // we have 3 real roots
- SkScalar theta = SkScalarACos(R / SkScalarSqrt(Q3));
+ // the divide/root can, due to finite precisions, be slightly outside of -1...1
+ SkScalar theta = SkScalarACos(SkScalarPin(R / SkScalarSqrt(Q3), -1, 1));
SkScalar neg2RootQ = -2 * SkScalarSqrt(Q);
r = neg2RootQ * SkScalarCos(theta/3) - adiv3;
diff --git a/src/pathops/SkPathOpsCubic.cpp b/src/pathops/SkPathOpsCubic.cpp
index 6b74fb00ef..a161e368e7 100644
--- a/src/pathops/SkPathOpsCubic.cpp
+++ b/src/pathops/SkPathOpsCubic.cpp
@@ -419,7 +419,8 @@ int SkDCubic::RootsReal(double A, double B, double C, double D, double s[3]) {
double r;
double* roots = s;
if (R2MinusQ3 < 0) { // we have 3 real roots
- double theta = acos(R / sqrt(Q3));
+ // the divide/root can, due to finite precisions, be slightly outside of -1...1
+ double theta = acos(SkTPin(R / sqrt(Q3), -1., 1.));
double neg2RootQ = -2 * sqrt(Q);
r = neg2RootQ * cos(theta / 3) - adiv3;