diff options
author | Mike Reed <reed@google.com> | 2018-05-14 16:51:32 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-05-14 21:14:09 +0000 |
commit | 026d20f888eb4223df65c22a94b7a25ae0eb39b6 (patch) | |
tree | 618c90c2b82b90d30d3aeb52bb37fd43597e6a6a /tests/MathTest.cpp | |
parent | 0cdfc32058dc8ce5e9c74326c2a5745671cb5a48 (diff) |
handle huge normalize requests (including non-finite x or y)
Bug: oss-fuzz:8023
Change-Id: I622b6e335d9efbe599fa9047b3a6fcee1664aa4a
Reviewed-on: https://skia-review.googlesource.com/124581
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'tests/MathTest.cpp')
-rw-r--r-- | tests/MathTest.cpp | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/tests/MathTest.cpp b/tests/MathTest.cpp index 565f76f819..b5d933d987 100644 --- a/tests/MathTest.cpp +++ b/tests/MathTest.cpp @@ -229,13 +229,9 @@ static void check_length(skiatest::Reporter* reporter, REPORTER_ASSERT(reporter, len > 0.999f && len < 1.001f); } -static float make_zero() { - return sk_float_sin(0); -} - static void unittest_isfinite(skiatest::Reporter* reporter) { float nan = sk_float_asin(2); - float inf = 1.0f / make_zero(); + float inf = SK_ScalarInfinity; float big = 3.40282e+038f; REPORTER_ASSERT(reporter, !SkScalarIsNaN(inf)); @@ -416,6 +412,21 @@ static void test_copysign(skiatest::Reporter* reporter) { } } +static void huge_vector_normalize(skiatest::Reporter* reporter) { + // these values should fail (overflow/underflow) trying to normalize + const SkVector fail[] = { + { 0, 0 }, + { SK_ScalarInfinity, 0 }, { 0, SK_ScalarInfinity }, + { 0, SK_ScalarNaN }, { SK_ScalarNaN, 0 }, + }; + for (SkVector v : fail) { + SkVector v2 = v; + if (v2.setLength(1.0f)) { + REPORTER_ASSERT(reporter, !v.setLength(1.0f)); + } + } +} + DEF_TEST(Math, reporter) { int i; SkRandom rand; @@ -488,6 +499,7 @@ DEF_TEST(Math, reporter) { REPORTER_ASSERT(reporter, (SkFixedCeilToFixed(-SK_Fixed1 * 10) >> 1) == -SK_Fixed1 * 5); } + huge_vector_normalize(reporter); unittest_isfinite(reporter); unittest_half(reporter); test_rsqrt(reporter, sk_float_rsqrt); |