skia2/fuzz/FuzzPathMeasure.cpp
Kevin Lubick 493f89e577 [fuzz] Standardize, document, and backport fuzzing defines.
We had several defines around the code base that were not
very descriptive. Additionally, we had a patch of extra
runtime restrictions living in oss-fuzz that were applied
when fuzzing over there for some fuzzers.

This has all be consolidated and controlled via the defines
documented in site/dev/testing/fuzz.md

As such, we can remove one of the patches that is in oss-fuzz,
taking us closer to being able to fuzz in the CI/CQ.

PS 1 renames existing fuzz defines to the new schema.
PS 2-3 backports skia.diff from oss-fuzz and changes those
definitions to have the _GREATLY modifier.
PS 5+ further condenses the defines so that there is one
define for gating the runtime checks.

Change-Id: Ia4ad96f30c1e9620a2123b510e97c6f501a2e257
Docs-Preview: https://skia.org/?cl=316443
Bug: skia:10713
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/316443
Commit-Queue: Kevin Lubick <kjlubick@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
2020-09-14 13:36:10 +00:00

39 lines
1.2 KiB
C++

/*
* Copyright 2018 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "fuzz/Fuzz.h"
#include "fuzz/FuzzCommon.h"
#include "include/core/SkPathMeasure.h"
void inline ignoreResult(bool ) {}
DEF_FUZZ(PathMeasure, fuzz) {
uint8_t bits;
fuzz->next(&bits);
SkScalar distance[6];
for (auto index = 0; index < 6; ++index) {
fuzz->next(&distance[index]);
}
SkPath path;
FuzzEvilPath(fuzz, &path, SkPath::Verb::kDone_Verb);
SkRect bounds = path.getBounds();
SkScalar maxDim = std::max(bounds.width(), bounds.height());
if (maxDim > 1000000) {
return;
}
SkScalar resScale = maxDim / 1000;
SkPathMeasure measure(path, bits & 1, resScale);
SkPoint position;
SkVector tangent;
ignoreResult(measure.getPosTan(distance[0], &position, &tangent));
SkPath dst;
ignoreResult(measure.getSegment(distance[1], distance[2], &dst, (bits >> 1) & 1));
ignoreResult(measure.nextContour());
ignoreResult(measure.getPosTan(distance[3], &position, &tangent));
ignoreResult(measure.getSegment(distance[4], distance[5], &dst, (bits >> 2) & 1));
}