2016-02-18 14:27:38 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "fuzz/Fuzz.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/utils/SkParsePath.h"
|
2018-09-19 15:31:27 +00:00
|
|
|
|
2016-02-18 14:27:38 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
// Most of this is taken from random_parse_path.cpp and adapted to use the Fuzz
|
|
|
|
// instead of SKRandom
|
|
|
|
|
2016-10-03 18:49:45 +00:00
|
|
|
static const struct Legal {
|
2016-02-18 14:27:38 +00:00
|
|
|
char fSymbol;
|
|
|
|
int fScalars;
|
|
|
|
} gLegal[] = {
|
|
|
|
{ 'M', 2 },
|
|
|
|
{ 'H', 1 },
|
|
|
|
{ 'V', 1 },
|
|
|
|
{ 'L', 2 },
|
|
|
|
{ 'Q', 4 },
|
|
|
|
{ 'T', 2 },
|
|
|
|
{ 'C', 6 },
|
|
|
|
{ 'S', 4 },
|
|
|
|
{ 'A', 4 },
|
|
|
|
{ 'Z', 0 },
|
|
|
|
};
|
|
|
|
|
2016-10-03 18:49:45 +00:00
|
|
|
static bool gEasy = false; // set to true while debugging to suppress unusual whitespace
|
2016-02-18 14:27:38 +00:00
|
|
|
|
|
|
|
// mostly do nothing, then bias towards spaces
|
2016-10-03 18:49:45 +00:00
|
|
|
static const char gWhiteSpace[] = { 0, 0, 0, 0, 0, 0, 0, 0, ' ', ' ', ' ', ' ', 0x09, 0x0D, 0x0A };
|
2016-02-18 14:27:38 +00:00
|
|
|
|
|
|
|
static void add_white(Fuzz* fuzz, SkString* atom) {
|
|
|
|
if (gEasy) {
|
|
|
|
atom->append(" ");
|
|
|
|
return;
|
|
|
|
}
|
2016-11-10 21:17:49 +00:00
|
|
|
// Use a uint8_t to conserve bytes. This makes our "fuzzed bytes footprint"
|
|
|
|
// smaller, which leads to more efficient fuzzing.
|
|
|
|
uint8_t reps;
|
|
|
|
fuzz->nextRange(&reps, 0, 2);
|
|
|
|
for (uint8_t rep = 0; rep < reps; ++rep) {
|
|
|
|
uint8_t index;
|
2016-11-15 21:07:02 +00:00
|
|
|
fuzz->nextRange(&index, 0, (int) SK_ARRAY_COUNT(gWhiteSpace) - 1);
|
2016-02-18 14:27:38 +00:00
|
|
|
if (gWhiteSpace[index]) {
|
|
|
|
atom->append(&gWhiteSpace[index], 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-01 19:01:12 +00:00
|
|
|
static void add_some_white(Fuzz* fuzz, SkString* atom) {
|
|
|
|
for(int i = 0; i < 10; i++) {
|
|
|
|
add_white(fuzz, atom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-18 14:27:38 +00:00
|
|
|
static void add_comma(Fuzz* fuzz, SkString* atom) {
|
|
|
|
if (gEasy) {
|
|
|
|
atom->append(",");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
add_white(fuzz, atom);
|
2016-11-10 21:17:49 +00:00
|
|
|
bool b;
|
|
|
|
fuzz->next(&b);
|
|
|
|
if (b) {
|
2016-02-18 14:27:38 +00:00
|
|
|
atom->append(",");
|
|
|
|
}
|
2016-11-01 19:01:12 +00:00
|
|
|
add_some_white(fuzz, atom);
|
2016-02-18 14:27:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SkString MakeRandomParsePathPiece(Fuzz* fuzz) {
|
|
|
|
SkString atom;
|
2016-11-10 21:17:49 +00:00
|
|
|
uint8_t index;
|
2016-11-15 21:07:02 +00:00
|
|
|
fuzz->nextRange(&index, 0, (int) SK_ARRAY_COUNT(gLegal) - 1);
|
2016-02-18 14:27:38 +00:00
|
|
|
const Legal& legal = gLegal[index];
|
|
|
|
gEasy ? atom.append("\n") : add_white(fuzz, &atom);
|
2016-11-10 21:17:49 +00:00
|
|
|
bool b;
|
|
|
|
fuzz->next(&b);
|
|
|
|
char symbol = legal.fSymbol | (b ? 0x20 : 0);
|
2016-02-18 14:27:38 +00:00
|
|
|
atom.append(&symbol, 1);
|
2016-11-10 21:17:49 +00:00
|
|
|
uint8_t reps;
|
|
|
|
fuzz->nextRange(&reps, 1, 3);
|
2016-02-18 14:27:38 +00:00
|
|
|
for (int rep = 0; rep < reps; ++rep) {
|
|
|
|
for (int index = 0; index < legal.fScalars; ++index) {
|
2016-11-10 21:17:49 +00:00
|
|
|
SkScalar coord;
|
|
|
|
fuzz->nextRange(&coord, 0.0f, 100.0f);
|
2016-02-18 14:27:38 +00:00
|
|
|
add_white(fuzz, &atom);
|
|
|
|
atom.appendScalar(coord);
|
|
|
|
if (rep < reps - 1 && index < legal.fScalars - 1) {
|
|
|
|
add_comma(fuzz, &atom);
|
|
|
|
} else {
|
|
|
|
add_some_white(fuzz, &atom);
|
|
|
|
}
|
|
|
|
if ('A' == legal.fSymbol && 1 == index) {
|
2016-11-10 21:17:49 +00:00
|
|
|
SkScalar s;
|
|
|
|
fuzz->nextRange(&s, -720.0f, 720.0f);
|
|
|
|
atom.appendScalar(s);
|
2016-02-18 14:27:38 +00:00
|
|
|
add_comma(fuzz, &atom);
|
2016-11-10 21:17:49 +00:00
|
|
|
fuzz->next(&b);
|
|
|
|
atom.appendU32(b);
|
2016-02-18 14:27:38 +00:00
|
|
|
add_comma(fuzz, &atom);
|
2016-11-10 21:17:49 +00:00
|
|
|
fuzz->next(&b);
|
|
|
|
atom.appendU32(b);
|
2016-02-18 14:27:38 +00:00
|
|
|
add_comma(fuzz, &atom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return atom;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_FUZZ(ParsePath, fuzz) {
|
|
|
|
SkPath path;
|
|
|
|
SkString spec;
|
2016-11-10 21:17:49 +00:00
|
|
|
uint8_t count;
|
|
|
|
fuzz->nextRange(&count, 0, 40);
|
|
|
|
for (uint8_t i = 0; i < count; ++i) {
|
2016-02-18 14:27:38 +00:00
|
|
|
spec.append(MakeRandomParsePathPiece(fuzz));
|
|
|
|
}
|
|
|
|
SkDebugf("SkParsePath::FromSVGString(%s, &path);\n",spec.c_str());
|
|
|
|
if (!SkParsePath::FromSVGString(spec.c_str(), &path)){
|
2016-11-01 19:01:12 +00:00
|
|
|
SkDebugf("Could not decode path\n");
|
2016-02-18 14:27:38 +00:00
|
|
|
}
|
|
|
|
}
|