From 026d20f888eb4223df65c22a94b7a25ae0eb39b6 Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Mon, 14 May 2018 16:51:32 -0400 Subject: 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 Commit-Queue: Mike Reed --- tests/MathTest.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'tests/MathTest.cpp') 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); -- cgit v1.2.3