-
Notifications
You must be signed in to change notification settings - Fork 8
/
10318.diff
291 lines (281 loc) · 10.1 KB
/
10318.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
commit 8051d38358293df1e5b8a1a513f8114147ec9fa3
Author: Robert Phillips <[email protected]>
Date: Thu Sep 13 08:22:15 2018 -0400
Fix SkPath::reverseAddPath and fuzzing of SkPath enums
Bug: 882423
Change-Id: I2be2863574a5951b86e4d5e213094efee6081098
Reviewed-on: https://skia-review.googlesource.com/154300
Reviewed-by: Kevin Lubick <[email protected]>
Reviewed-by: Greg Daniel <[email protected]>
Commit-Queue: Robert Phillips <[email protected]>
diff --git a/fuzz/FuzzCommon.cpp b/fuzz/FuzzCommon.cpp
index 8176d7fb55..d6aa94eb86 100644
--- a/fuzz/FuzzCommon.cpp
+++ b/fuzz/FuzzCommon.cpp
@@ -11,170 +11,187 @@
// allows some float values for path points
void FuzzPath(Fuzz* fuzz, SkPath* path, int maxOps) {
if (maxOps <= 0) {
return;
}
uint8_t fillType;
fuzz->nextRange(&fillType, 0, (uint8_t)SkPath::kInverseEvenOdd_FillType);
path->setFillType((SkPath::FillType)fillType);
uint8_t numOps;
fuzz->nextRange(&numOps, 0, maxOps);
for (uint8_t i = 0; i < numOps; ++i) {
uint8_t op;
fuzz->nextRange(&op, 0, 32);
bool test;
SkPath p;
SkMatrix m;
SkRRect rr;
SkRect r;
SkPath::Direction dir;
unsigned int ui;
SkScalar a, b, c, d, e, f;
switch (op) {
case 0:
fuzz_nice_float(fuzz, &a, &b);
path->moveTo(a, b);
break;
case 1:
fuzz_nice_float(fuzz, &a, &b);
path->rMoveTo(a, b);
break;
case 2:
fuzz_nice_float(fuzz, &a, &b);
path->lineTo(a, b);
break;
case 3:
fuzz_nice_float(fuzz, &a, &b);
path->rLineTo(a, b);
break;
case 4:
fuzz_nice_float(fuzz, &a, &b, &c, &d);
path->quadTo(a, b, c, d);
break;
case 5:
fuzz_nice_float(fuzz, &a, &b, &c, &d);
path->rQuadTo(a, b, c, d);
break;
case 6:
fuzz_nice_float(fuzz, &a, &b, &c, &d, &e);
path->conicTo(a, b, c, d, e);
break;
case 7:
fuzz_nice_float(fuzz, &a, &b, &c, &d, &e);
path->rConicTo(a, b, c, d, e);
break;
case 8:
fuzz_nice_float(fuzz, &a, &b, &c, &d, &e, &f);
path->cubicTo(a, b, c, d, e, f);
break;
case 9:
fuzz_nice_float(fuzz, &a, &b, &c, &d, &e, &f);
path->rCubicTo(a, b, c, d, e, f);
break;
case 10:
fuzz_nice_float(fuzz, &a, &b, &c, &d, &e);
path->arcTo(a, b, c, d, e);
break;
case 11:
fuzz_nice_float(fuzz, &a, &b);
fuzz->next(&r, &test);
path->arcTo(r, a, b, test);
break;
case 12:
path->close();
break;
case 13:
- fuzz->next(&r, &dir);
+ fuzz->next(&r);
+ fuzz->nextRange(&ui, 0, 1);
+ dir = static_cast<SkPath::Direction>(ui);
path->addRect(r, dir);
break;
case 14:
- fuzz->next(&r, &dir, &ui);
+ fuzz->nextRange(&ui, 0, 1);
+ dir = static_cast<SkPath::Direction>(ui);
+ fuzz->next(&r, &ui);
path->addRect(r, dir, ui);
break;
case 15:
- fuzz->next(&r, &dir);
+ fuzz->nextRange(&ui, 0, 1);
+ dir = static_cast<SkPath::Direction>(ui);
+ fuzz->next(&r);
path->addOval(r, dir);
break;
case 16:
- fuzz->next(&r, &dir, &ui);
+ fuzz->nextRange(&ui, 0, 1);
+ dir = static_cast<SkPath::Direction>(ui);
+ fuzz->next(&r, &ui);
path->addOval(r, dir, ui);
break;
case 17:
+ fuzz->nextRange(&ui, 0, 1);
+ dir = static_cast<SkPath::Direction>(ui);
fuzz_nice_float(fuzz, &a, &b, &c);
- fuzz->next(&dir);
path->addCircle(a, b, c, dir);
break;
case 18:
fuzz->next(&r);
fuzz_nice_float(fuzz, &a, &b);
path->addArc(r, a, b);
break;
case 19:
fuzz_nice_float(fuzz, &a, &b);
- fuzz->next(&r, &dir);
+ fuzz->next(&r);
+ fuzz->nextRange(&ui, 0, 1);
+ dir = static_cast<SkPath::Direction>(ui);
path->addRoundRect(r, a, b, dir);
break;
case 20:
- fuzz->next(&rr, &dir);
+ fuzz->next(&rr);
+ fuzz->nextRange(&ui, 0, 1);
+ dir = static_cast<SkPath::Direction>(ui);
path->addRRect(rr, dir);
break;
case 21:
- fuzz->next(&rr, &dir, &ui);
+ fuzz->nextRange(&ui, 0, 1);
+ dir = static_cast<SkPath::Direction>(ui);
+ fuzz->next(&rr, &ui);
path->addRRect(rr, dir, ui);
break;
case 22: {
- SkPath::AddPathMode mode;
- fuzz->next(&m, &mode);
+ fuzz->nextRange(&ui, 0, 1);
+ SkPath::AddPathMode mode = static_cast<SkPath::AddPathMode>(ui);
+ fuzz->next(&m);
FuzzPath(fuzz, &p, maxOps-1);
path->addPath(p, m, mode);
break;
}
case 23: {
- SkPath::AddPathMode mode;
- fuzz->next(&m, &mode);
+ fuzz->nextRange(&ui, 0, 1);
+ SkPath::AddPathMode mode = static_cast<SkPath::AddPathMode>(ui);
+ fuzz->next(&m);
path->addPath(*path, m, mode);
break;
}
case 24:
FuzzPath(fuzz, &p, maxOps-1);
path->reverseAddPath(p);
break;
case 25:
path->addPath(*path);
break;
case 26:
path->reverseAddPath(*path);
break;
case 27:
fuzz_nice_float(fuzz, &a, &b);
path->offset(a, b, path);
break;
case 28:
FuzzPath(fuzz, &p, maxOps-1);
fuzz_nice_float(fuzz, &a, &b);
p.offset(a, b, path);
break;
case 29:
fuzz->next(&m);
path->transform(m, path);
break;
case 30:
FuzzPath(fuzz, &p, maxOps-1);
fuzz->next(&m);
p.transform(m, path);
break;
case 31:
fuzz_nice_float(fuzz, &a, &b);
path->setLastPt(a, b);
break;
case 32:
path->shrinkToFit();
break;
default:
SkASSERT(false);
break;
}
}
}
// allows all float values for path points
diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp
index 34704774b0..2808c12ed4 100644
--- a/src/core/SkPath.cpp
+++ b/src/core/SkPath.cpp
@@ -1708,56 +1708,63 @@ SkPath& SkPath::reversePathTo(const SkPath& path) {
return *this;
}
-SkPath& SkPath::reverseAddPath(const SkPath& src) {
- SkPathRef::Editor ed(&fPathRef, src.fPathRef->countPoints(), src.fPathRef->countVerbs());
+SkPath& SkPath::reverseAddPath(const SkPath& srcPath) {
+ // Detect if we're trying to add ourself
+ const SkPath* src = &srcPath;
+ SkTLazy<SkPath> tmp;
+ if (this == src) {
+ src = tmp.set(srcPath);
+ }
+
+ SkPathRef::Editor ed(&fPathRef, src->fPathRef->countPoints(), src->fPathRef->countVerbs());
- const SkPoint* pts = src.fPathRef->pointsEnd();
+ const SkPoint* pts = src->fPathRef->pointsEnd();
// we will iterator through src's verbs backwards
- const uint8_t* verbs = src.fPathRef->verbsMemBegin(); // points at the last verb
- const uint8_t* verbsEnd = src.fPathRef->verbs(); // points just past the first verb
- const SkScalar* conicWeights = src.fPathRef->conicWeightsEnd();
+ const uint8_t* verbs = src->fPathRef->verbsMemBegin(); // points at the last verb
+ const uint8_t* verbsEnd = src->fPathRef->verbs(); // points just past the first verb
+ const SkScalar* conicWeights = src->fPathRef->conicWeightsEnd();
bool needMove = true;
bool needClose = false;
while (verbs < verbsEnd) {
uint8_t v = *(verbs++);
int n = pts_in_verb(v);
if (needMove) {
--pts;
this->moveTo(pts->fX, pts->fY);
needMove = false;
}
pts -= n;
switch (v) {
case kMove_Verb:
if (needClose) {
this->close();
needClose = false;
}
needMove = true;
pts += 1; // so we see the point in "if (needMove)" above
break;
case kLine_Verb:
this->lineTo(pts[0]);
break;
case kQuad_Verb:
this->quadTo(pts[1], pts[0]);
break;
case kConic_Verb:
this->conicTo(pts[1], pts[0], *--conicWeights);
break;
case kCubic_Verb:
this->cubicTo(pts[2], pts[1], pts[0]);
break;
case kClose_Verb:
needClose = true;
break;
default:
SkDEBUGFAIL("unexpected verb");
}
}
return *this;
}
///////////////////////////////////////////////////////////////////////////////