diff options
author | fmalita <fmalita@chromium.org> | 2016-08-10 05:45:50 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-10 05:45:50 -0700 |
commit | c52310402c56e535e574a0a53e2355e5350e952d (patch) | |
tree | f92fd173158b15c7b4196b5c63e8339f47274a1e | |
parent | 75ccdc77a70ec2083141bf9ba98eb2f01ece2479 (diff) |
Prevent degenerate linear gradient instantiation
If the point distance exceeds SkScalar, nasty things tend to happen.
R=reed@google.com
BUG=636194
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2234663002
Review-Url: https://codereview.chromium.org/2234663002
-rw-r--r-- | src/effects/gradients/SkGradientShader.cpp | 2 | ||||
-rw-r--r-- | tests/GradientTest.cpp | 17 |
2 files changed, 18 insertions, 1 deletions
diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp index 710bde826e..820c5b225d 100644 --- a/src/effects/gradients/SkGradientShader.cpp +++ b/src/effects/gradients/SkGradientShader.cpp @@ -790,7 +790,7 @@ sk_sp<SkShader> SkGradientShader::MakeLinear(const SkPoint pts[2], SkShader::TileMode mode, uint32_t flags, const SkMatrix* localMatrix) { - if (!pts) { + if (!pts || !SkScalarIsFinite((pts[1] - pts[0]).length())) { return nullptr; } if (!valid_grad(colors, pos, colorCount, mode)) { diff --git a/tests/GradientTest.cpp b/tests/GradientTest.cpp index 7add42d875..3ed2f518cc 100644 --- a/tests/GradientTest.cpp +++ b/tests/GradientTest.cpp @@ -253,6 +253,22 @@ static void test_clamping_overflow(skiatest::Reporter*) { // Passes if we don't trigger asserts. } +// http://crbug.com/636194 +static void text_degenerate_linear(skiatest::Reporter*) { + SkPaint p; + const SkColor colors[] = { SK_ColorRED, SK_ColorGREEN }; + const SkPoint pts[] = { + SkPoint::Make(-46058024627067344430605278824628224.0f, 0), + SkPoint::Make(SK_ScalarMax, 0) + }; + + p.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode)); + sk_sp<SkSurface> surface(SkSurface::MakeRasterN32Premul(50, 50)); + surface->getCanvas()->drawPaint(p); + + // Passes if we don't trigger asserts. +} + DEF_TEST(Gradient, reporter) { TestGradientShaders(reporter); TestConstantGradient(reporter); @@ -261,4 +277,5 @@ DEF_TEST(Gradient, reporter) { test_linear_fuzz(reporter); test_two_point_conical_zero_radius(reporter); test_clamping_overflow(reporter); + text_degenerate_linear(reporter); } |