Cary Clark | 91390c8 | 2018-03-09 14:02:46 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "fuzz/Fuzz.h" |
| 9 | #include "fuzz/FuzzCommon.h" |
| 10 | #include "include/core/SkPathMeasure.h" |
Cary Clark | 91390c8 | 2018-03-09 14:02:46 -0500 | [diff] [blame] | 11 | |
| 12 | void inline ignoreResult(bool ) {} |
| 13 | |
| 14 | DEF_FUZZ(PathMeasure, fuzz) { |
| 15 | uint8_t bits; |
| 16 | fuzz->next(&bits); |
| 17 | SkScalar distance[6]; |
| 18 | for (auto index = 0; index < 6; ++index) { |
| 19 | fuzz->next(&distance[index]); |
| 20 | } |
| 21 | SkPath path; |
Mike Klein | 7ffa40c | 2018-09-25 12:16:53 -0400 | [diff] [blame] | 22 | FuzzEvilPath(fuzz, &path, SkPath::Verb::kDone_Verb); |
Cary Clark | 91390c8 | 2018-03-09 14:02:46 -0500 | [diff] [blame] | 23 | SkRect bounds = path.getBounds(); |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 24 | SkScalar maxDim = std::max(bounds.width(), bounds.height()); |
Kevin Lubick | 493f89e | 2020-09-14 08:37:35 -0400 | [diff] [blame] | 25 | if (maxDim > 1000000) { |
| 26 | return; |
| 27 | } |
Cary Clark | 91390c8 | 2018-03-09 14:02:46 -0500 | [diff] [blame] | 28 | SkScalar resScale = maxDim / 1000; |
| 29 | SkPathMeasure measure(path, bits & 1, resScale); |
| 30 | SkPoint position; |
| 31 | SkVector tangent; |
| 32 | ignoreResult(measure.getPosTan(distance[0], &position, &tangent)); |
| 33 | SkPath dst; |
| 34 | ignoreResult(measure.getSegment(distance[1], distance[2], &dst, (bits >> 1) & 1)); |
| 35 | ignoreResult(measure.nextContour()); |
| 36 | ignoreResult(measure.getPosTan(distance[3], &position, &tangent)); |
| 37 | ignoreResult(measure.getSegment(distance[4], distance[5], &dst, (bits >> 2) & 1)); |
| 38 | } |