Limit offset range when fuzzing SkOffsetSimplePolygon

Bug: oss-fuzz:43699
Change-Id: Ie856aed03b513a4ea84a09deda6a05b95b086b07
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/496876
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
This commit is contained in:
Jim Van Verth 2022-01-20 15:25:14 -05:00 committed by SkCQ
parent 42bfd747a7
commit 62bb436301
3 changed files with 10 additions and 5 deletions

View File

@ -44,7 +44,9 @@ DEF_FUZZ(PolyUtils, fuzz) {
if (isSimple) {
SkScalar offset;
fuzz->next(&offset);
// Limit this to prevent timeouts.
// This should be fine, as this is roughly the range we expect from the shadow algorithm.
fuzz->nextRange(&offset, -1000, 1000);
ignoreResult(SkOffsetSimplePolygon(polygon, count, bounds, offset, &output));
SkAutoSTMalloc<64, uint16_t> indexMap(count);

View File

@ -13,6 +13,7 @@
#include "include/private/SkTArray.h"
#include "include/private/SkTemplates.h"
#include "src/core/SkPointPriv.h"
#include "src/core/SkRectPriv.h"
#include "src/core/SkTDPQueue.h"
#include "src/core/SkTInternalLList.h"
@ -1179,8 +1180,8 @@ bool SkOffsetSimplePolygon(const SkPoint* inputPolygonVerts, int inputPolygonSiz
}
// can't inset more than the half bounds of the polygon
if (offset > std::min(SkTAbs(SK_ScalarHalf*bounds.width()),
SkTAbs(SK_ScalarHalf*bounds.height()))) {
if (offset > std::min(SkTAbs(SkRectPriv::HalfWidth(bounds)),
SkTAbs(SkRectPriv::HalfHeight(bounds)))) {
return false;
}

View File

@ -13,6 +13,7 @@
#include "src/core/SkDrawShadowInfo.h"
#include "src/core/SkGeometry.h"
#include "src/core/SkPointPriv.h"
#include "src/core/SkRectPriv.h"
#include "src/utils/SkPolyUtils.h"
#include "src/utils/SkShadowTessellator.h"
@ -555,6 +556,9 @@ bool SkBaseShadowTessellator::computeConcaveShadow(SkScalar inset, SkScalar outs
return false;
}
// shouldn't inset more than the half bounds of the polygon
inset = std::min(inset, std::min(SkTAbs(SkRectPriv::HalfWidth(fPathBounds)),
SkTAbs(SkRectPriv::HalfHeight(fPathBounds))));
// generate inner ring
SkTDArray<SkPoint> umbraPolygon;
SkTDArray<int> umbraIndices;
@ -910,8 +914,6 @@ SkAmbientShadowTessellator::SkAmbientShadowTessellator(const SkPath& path,
// umbraColor is the interior value, penumbraColor the exterior value.
auto outset = SkDrawShadowMetrics::AmbientBlurRadius(baseZ);
auto inset = outset * SkDrawShadowMetrics::AmbientRecipAlpha(baseZ) - outset;
inset = SkTPin(inset, 0.0f, std::min(path.getBounds().width(),
path.getBounds().height()));
if (!this->computePathPolygon(path, ctm)) {
return;