Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions | Variables
FuzzPathop.cpp File Reference
#include "fuzz/Fuzz.h"
#include "fuzz/FuzzCommon.h"
#include "include/core/SkPath.h"
#include "include/core/SkRect.h"
#include "include/pathops/SkPathOps.h"

Go to the source code of this file.

Functions

 DEF_FUZZ (Pathop, fuzz)
 
void BuildPath (Fuzz *fuzz, SkPath *path)
 
 DEF_FUZZ (LegacyChromiumPathop, fuzz)
 

Variables

const uint8_t MAX_OPS = 20
 
const int kLastOp = SkPathOp::kReverseDifference_SkPathOp
 

Function Documentation

◆ BuildPath()

void BuildPath ( Fuzz fuzz,
SkPath path 
)

Definition at line 120 of file FuzzPathop.cpp.

120 {
121 while (!fuzz->exhausted()) {
122 // Use a uint8_t to conserve bytes. This makes our "fuzzed bytes footprint"
123 // smaller, which leads to more efficient fuzzing.
124 uint8_t operation;
125 fuzz->next(&operation);
126 SkScalar a,b,c,d,e,f;
127
128 switch (operation % (SkPath::Verb::kDone_Verb + 1)) {
130 if (fuzz->remainingSize() < (2*sizeof(SkScalar))) {
131 fuzz->deplete();
132 return;
133 }
134 fuzz->next(&a, &b);
135 path->moveTo(a, b);
136 break;
137
139 if (fuzz->remainingSize() < (2*sizeof(SkScalar))) {
140 fuzz->deplete();
141 return;
142 }
143 fuzz->next(&a, &b);
144 path->lineTo(a, b);
145 break;
146
148 if (fuzz->remainingSize() < (4*sizeof(SkScalar))) {
149 fuzz->deplete();
150 return;
151 }
152 fuzz->next(&a, &b, &c, &d);
153 path->quadTo(a, b, c, d);
154 break;
155
157 if (fuzz->remainingSize() < (5*sizeof(SkScalar))) {
158 fuzz->deplete();
159 return;
160 }
161 fuzz->next(&a, &b, &c, &d, &e);
162 path->conicTo(a, b, c, d, e);
163 break;
164
166 if (fuzz->remainingSize() < (6*sizeof(SkScalar))) {
167 fuzz->deplete();
168 return;
169 }
170 fuzz->next(&a, &b, &c, &d, &e, &f);
171 path->cubicTo(a, b, c, d, e, f);
172 break;
173
175 path->close();
176 break;
177
179 // In this case, simply exit.
180 return;
181 }
182 }
183}
static void operation(T operation, uint32_t &a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint8_t s, uint32_t t)
Definition SkMD5.cpp:144
void next(T *t)
Definition Fuzz.h:64
size_t remainingSize() const
Definition Fuzz.h:47
void deplete()
Definition Fuzz.h:43
bool exhausted() const
Definition Fuzz.h:39
@ kClose_Verb
Definition SkPath.h:1463
@ kMove_Verb
Definition SkPath.h:1458
@ kConic_Verb
Definition SkPath.h:1461
@ kDone_Verb
Definition SkPath.h:1464
@ kCubic_Verb
Definition SkPath.h:1462
@ kQuad_Verb
Definition SkPath.h:1460
@ kLine_Verb
Definition SkPath.h:1459
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition main.cc:19
float SkScalar
Definition extension.cpp:12
static bool b
struct MyStruct a[10]
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition switches.h:57

◆ DEF_FUZZ() [1/2]

DEF_FUZZ ( LegacyChromiumPathop  ,
fuzz   
)

Definition at line 185 of file FuzzPathop.cpp.

185 {
186 // See https://cs.chromium.org/chromium/src/testing/libfuzzer/fuzzers/skia_pathop_fuzzer.cc
188 while (!fuzz->exhausted()) {
189 SkPath path;
190 uint8_t op;
191 fuzz->next(&op);
192 if (fuzz->exhausted()) {
193 break;
194 }
195
196 BuildPath(fuzz, &path);
197 builder.add(path, static_cast<SkPathOp>(op % (kLastOp + 1)));
198 }
199
201 builder.resolve(&result);
202}
void BuildPath(Fuzz *fuzz, SkPath *path)
const int kLastOp
SkPathOp
Definition SkPathOps.h:22
GAsyncResult * result

◆ DEF_FUZZ() [2/2]

DEF_FUZZ ( Pathop  ,
fuzz   
)

Definition at line 16 of file FuzzPathop.cpp.

16 {
17
18 uint8_t choice;
19 fuzz->nextRange(&choice, 0, 4);
20 switch (choice) {
21 case 0: {
22 uint8_t ops;
23 fuzz->nextRange(&ops, 0, MAX_OPS);
25 for (uint8_t i = 0; i < ops && !fuzz->exhausted(); i++) {
29 fuzz->nextRange(&ft, 0, (int)SkPathFillType::kInverseEvenOdd);
30 path.setFillType(ft);
31
32 SkPathOp op;
33 fuzz->nextRange(&op, 0, SkPathOp::kReverseDifference_SkPathOp);
34 builder.add(path, op);
35 }
36
38 builder.resolve(&result);
39 break;
40 }
41 case 1: {
45 fuzz->nextRange(&ft, 0, (int)SkPathFillType::kInverseEvenOdd);
46 path.setFillType(ft);
47
49 bool isSame;
50 fuzz->next(&isSame);
51 if (isSame) {
52 result = path;
53 }
54 Simplify(path, &result);
55 break;
56 }
57 case 2: {
61 fuzz->nextRange(&ft, 0, SkPathFillType::kInverseEvenOdd);
62 path.setFillType(ft);
63
66 fuzz->nextRange(&ft, 0, SkPathFillType::kInverseEvenOdd);
67 path.setFillType(ft);
68
69 SkPathOp op;
70 fuzz->nextRange(&op, 0, SkPathOp::kReverseDifference_SkPathOp);
71
73 uint8_t pickOutput;
74 fuzz->nextRange(&pickOutput, 0, 2);
75 if (pickOutput == 1) {
76 result = path;
77 } else if (pickOutput == 2) {
78 result = path2;
79 }
80 Op(path, path2, op, &result);
81 break;
82 }
83 case 3: {
87 fuzz->nextRange(&ft, 0, SkPathFillType::kInverseEvenOdd);
88 path.setFillType(ft);
89
91 bool isSame;
92 fuzz->next(&isSame);
93 if (isSame) {
94 result = path;
95 }
96 AsWinding(path, &result);
97 break;
98 }
99 case 4: {
100 SkPath path;
103 fuzz->nextRange(&ft, 0, SkPathFillType::kInverseEvenOdd);
104 path.setFillType(ft);
105
107 TightBounds(path, &result);
108 break;
109 }
110 default: {
111 SkASSERT(false);
112 break;
113 }
114 }
115}
void FuzzEvilPath(Fuzz *fuzz, SkPath *path, int last_verb)
const uint8_t MAX_OPS
static SkPath path2()
SkPathOp ops[]
#define SkASSERT(cond)
Definition SkAssert.h:116
bool SK_API AsWinding(const SkPath &path, SkPath *result)
@ kReverseDifference_SkPathOp
subtract the first path from the op path
Definition SkPathOps.h:27
bool SK_API Simplify(const SkPath &path, SkPath *result)
bool SK_API TightBounds(const SkPath &path, SkRect *result)
SkPathFillType
Definition SkPathTypes.h:11

Variable Documentation

◆ kLastOp

Definition at line 118 of file FuzzPathop.cpp.

◆ MAX_OPS

const uint8_t MAX_OPS = 20

Definition at line 14 of file FuzzPathop.cpp.