From a35ab3e6e024d0b548ded26a2e3b8ecd838ead93 Mon Sep 17 00:00:00 2001 From: caryclark Date: Thu, 20 Oct 2016 08:32:18 -0700 Subject: fix fuzzers Many old pathops-related fuzz failures have built up while the codebase was under a state a flux. Now that the code is stable, address these failures. Most of the CL plumbs the debug global state to downstream routines so that, if the data is not trusted (ala fuzzed) the function can safely exit without asserting. TBR=reed@google.com GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2426173002 Review-Url: https://chromiumcodereview.appspot.com/2426173002 --- tests/PathOpsCubicIntersectionTest.cpp | 122 ++++++++++++++++++--------------- 1 file changed, 67 insertions(+), 55 deletions(-) (limited to 'tests/PathOpsCubicIntersectionTest.cpp') diff --git a/tests/PathOpsCubicIntersectionTest.cpp b/tests/PathOpsCubicIntersectionTest.cpp index 07852bca9a..e69aff86a5 100644 --- a/tests/PathOpsCubicIntersectionTest.cpp +++ b/tests/PathOpsCubicIntersectionTest.cpp @@ -19,11 +19,14 @@ const int firstCubicIntersectionTest = 9; static void standardTestCases(skiatest::Reporter* reporter) { for (size_t index = firstCubicIntersectionTest; index < tests_count; ++index) { int iIndex = static_cast(index); - const SkDCubic& cubic1 = tests[index][0]; - const SkDCubic& cubic2 = tests[index][1]; + const CubicPts& cubic1 = tests[index][0]; + const CubicPts& cubic2 = tests[index][1]; + SkDCubic c1, c2; + c1.debugSet(cubic1.fPts); + c2.debugSet(cubic2.fPts); SkReduceOrder reduce1, reduce2; - int order1 = reduce1.reduce(cubic1, SkReduceOrder::kNo_Quadratics); - int order2 = reduce2.reduce(cubic2, SkReduceOrder::kNo_Quadratics); + int order1 = reduce1.reduce(c1, SkReduceOrder::kNo_Quadratics); + int order2 = reduce2.reduce(c2, SkReduceOrder::kNo_Quadratics); const bool showSkipped = false; if (order1 < 4) { if (showSkipped) { @@ -38,7 +41,7 @@ static void standardTestCases(skiatest::Reporter* reporter) { continue; } SkIntersections tIntersections; - tIntersections.intersect(cubic1, cubic2); + tIntersections.intersect(c1, c2); if (!tIntersections.used()) { if (showSkipped) { SkDebugf("%s [%d] no intersection\n", __FUNCTION__, iIndex); @@ -53,9 +56,9 @@ static void standardTestCases(skiatest::Reporter* reporter) { } for (int pt = 0; pt < tIntersections.used(); ++pt) { double tt1 = tIntersections[0][pt]; - SkDPoint xy1 = cubic1.ptAtT(tt1); + SkDPoint xy1 = c1.ptAtT(tt1); double tt2 = tIntersections[1][pt]; - SkDPoint xy2 = cubic2.ptAtT(tt2); + SkDPoint xy2 = c2.ptAtT(tt2); if (!xy1.approximatelyEqual(xy2)) { SkDebugf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n", __FUNCTION__, (int)index, pt, tt1, xy1.fX, xy1.fY, tt2, xy2.fX, xy2.fY); @@ -66,7 +69,7 @@ static void standardTestCases(skiatest::Reporter* reporter) { } } -static const SkDCubic testSet[] = { +static const CubicPts testSet[] = { // FIXME: uncommenting these two will cause this to fail // this results in two curves very nearly but not exactly coincident #if 0 @@ -164,7 +167,7 @@ static const SkDCubic testSet[] = { const int testSetCount = (int) SK_ARRAY_COUNT(testSet); -static const SkDCubic newTestSet[] = { +static const CubicPts newTestSet[] = { { { { 130.0427549999999997, 11417.41309999999976 },{ 130.2331240000000037, 11418.3192999999992 },{ 131.0370790000000056, 11419 },{ 132, 11419 } } }, { { { 132, 11419 },{ 130.8954319999999996, 11419 },{ 130, 11418.10449999999946 },{ 130, 11417 } } }, @@ -381,10 +384,13 @@ static const SkDCubic newTestSet[] = { }; const int newTestSetCount = (int) SK_ARRAY_COUNT(newTestSet); -static void oneOff(skiatest::Reporter* reporter, const SkDCubic& cubic1, const SkDCubic& cubic2, +static void oneOff(skiatest::Reporter* reporter, const CubicPts& cubic1, const CubicPts& cubic2, bool coin) { - SkASSERT(ValidCubic(cubic1)); - SkASSERT(ValidCubic(cubic2)); + SkDCubic c1, c2; + c1.debugSet(cubic1.fPts); + c2.debugSet(cubic2.fPts); + SkASSERT(ValidCubic(c1)); + SkASSERT(ValidCubic(c2)); #if ONE_OFF_DEBUG SkDebugf("computed quadratics given\n"); SkDebugf(" {{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", @@ -395,7 +401,7 @@ static void oneOff(skiatest::Reporter* reporter, const SkDCubic& cubic1, const S cubic2[2].fX, cubic2[2].fY, cubic2[3].fX, cubic2[3].fY); #endif SkIntersections intersections; - intersections.intersect(cubic1, cubic2); + intersections.intersect(c1, c2); #if DEBUG_T_SECT_DUMP == 3 SkDebugf("\n\n"); SkDebugf("