From 3054989426549ba1dac83d3b84bf28d118edf75d Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Fri, 24 Aug 2018 17:11:28 -0400 Subject: [PATCH] do reject vertical lines if they are outside of the clip Bug: skia:7981 Change-Id: Icae11ac2934bc6db5a5c3ad0f17aaf615efa2fe5 Reviewed-on: https://skia-review.googlesource.com/149291 Auto-Submit: Mike Reed Commit-Queue: Cary Clark Reviewed-by: Cary Clark --- src/core/SkLineClipper.cpp | 10 ++++++---- tests/ClipperTest.cpp | 11 +++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/core/SkLineClipper.cpp b/src/core/SkLineClipper.cpp index d7c75c362f965..54ba47dbc1eb0 100644 --- a/src/core/SkLineClipper.cpp +++ b/src/core/SkLineClipper.cpp @@ -137,10 +137,12 @@ bool SkLineClipper::IntersectLine(const SkPoint src[2], const SkRect& clip, } // check for quick-reject in X again, now that we may have been chopped - if ((tmp[index1].fX <= clip.fLeft || tmp[index0].fX >= clip.fRight) && - tmp[index0].fX < tmp[index1].fX) { - // only reject if we have a non-zero width - return false; + if ((tmp[index1].fX <= clip.fLeft || tmp[index0].fX >= clip.fRight)) { + // usually we will return false, but we don't if the line is vertical and coincident + // with the clip. + if (tmp[0].fX != tmp[1].fX || tmp[0].fX < clip.fLeft || tmp[0].fX > clip.fRight) { + return false; + } } if (tmp[index0].fX < clip.fLeft) { diff --git a/tests/ClipperTest.cpp b/tests/ClipperTest.cpp index 0bb5212581013..3cebd7871c55a 100644 --- a/tests/ClipperTest.cpp +++ b/tests/ClipperTest.cpp @@ -156,3 +156,14 @@ DEF_TEST(Clipper, reporter) { test_edgeclipper(); test_hairclipping(reporter); } + +#include "SkLineClipper.h" + +DEF_TEST(LineClipper_skbug_7981, r) { + SkPoint src[] = {{ -5.77698802E+17f, -1.81758057E+23f}, {38127, 2}}; + SkPoint dst[2]; + SkRect clip = { -32767, -32767, 32767, 32767 }; + + SkLineClipper::IntersectLine(src, clip, dst); +} +