Skip to content

Commit

Permalink
Handle dividing by zero in ComputeComplexity
Browse files Browse the repository at this point in the history
Bug: oss-fuzz:9884
Change-Id: Ibeeb1ffdb46d9a648c7ec8944424af2d0138af59
Reviewed-on: https://skia-review.googlesource.com/156631
Commit-Queue: Yuqian Li <[email protected]>
Reviewed-by: Mike Klein <[email protected]>
Auto-Submit: Yuqian Li <[email protected]>
  • Loading branch information
liyuqian authored and Skia Commit-Bot committed Sep 25, 2018
1 parent f18c297 commit bd03b54
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/core/SkRect.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ struct SK_API SkIRect {
*/
bool isEmpty64() const { return fRight <= fLeft || fBottom <= fTop; }

/** Returns true if width() or height() .
/** Returns true if width() or height() are zero or negative.
@return true if width() or height() are zero or negative
*/
Expand Down
13 changes: 8 additions & 5 deletions src/core/SkScan_AntiPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,10 +609,9 @@ static inline SkScalar sqr(SkScalar x) {

static void ComputeComplexity(const SkPath& path, SkScalar& avgLength, SkScalar& complexity) {
int n = path.countPoints();
if (n < kSampleSize) {
if (n < kSampleSize || path.getBounds().isEmpty()) {
// set to invalid value to indicate that we failed to compute
avgLength = -1;
complexity = -1;
avgLength = complexity = -1;
return;
}

Expand All @@ -629,10 +628,14 @@ static void ComputeComplexity(const SkPath& path, SkScalar& avgLength, SkScalar&

// If the path consists of random line segments, the number of intersections should be
// proportional to this.
SkScalar intersections = sqr(n) * sqr(avgLength) / diagonalSqr;
SkScalar intersections = sk_ieee_float_divide(sqr(n) * sqr(avgLength), diagonalSqr);

// The number of intersections per scanline should be proportional to this number.
complexity = intersections / path.getBounds().height();
complexity = sk_ieee_float_divide(intersections, path.getBounds().height());

if (sk_float_isnan(complexity)) { // it may be possible to have 0.0 / 0.0; inf is fine for us.
complexity = -1;
}
}

static bool ShouldUseDAA(const SkPath& path, SkScalar avgLength, SkScalar complexity) {
Expand Down

0 comments on commit bd03b54

Please sign in to comment.