aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2016-02-22 12:50:25 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-02-22 12:50:26 -0800
commitca726abe1e4a2522b24e5143c5faf0e594a4802a (patch)
tree82aeae3da478bb96e94d8c152ec9646baa799ba9
parentd49a86ade0bab1fc3048d6ba5d8536abf25ed77c (diff)
fix misc asserts and checks found by fuzzer
-rw-r--r--include/core/SkPathEffect.h16
-rw-r--r--include/effects/Sk1DPathEffect.h6
-rw-r--r--include/effects/SkAlphaThresholdFilter.h4
-rw-r--r--include/effects/SkDashPathEffect.h7
-rw-r--r--samplecode/SampleFilterFuzz.cpp13
-rw-r--r--src/effects/Sk1DPathEffect.cpp60
-rw-r--r--src/effects/SkAlphaThresholdFilter.cpp9
-rw-r--r--src/effects/SkDashPathEffect.cpp14
8 files changed, 84 insertions, 45 deletions
diff --git a/include/core/SkPathEffect.h b/include/core/SkPathEffect.h
index bd68c8fa72..a77b9467e4 100644
--- a/include/core/SkPathEffect.h
+++ b/include/core/SkPathEffect.h
@@ -183,7 +183,13 @@ public:
The reference counts for outer and inner are both incremented in the constructor,
and decremented in the destructor.
*/
- static SkComposePathEffect* Create(SkPathEffect* outer, SkPathEffect* inner) {
+ static SkPathEffect* Create(SkPathEffect* outer, SkPathEffect* inner) {
+ if (!outer) {
+ return SkSafeRef(inner);
+ }
+ if (!inner) {
+ return SkSafeRef(outer);
+ }
return new SkComposePathEffect(outer, inner);
}
@@ -220,7 +226,13 @@ public:
The reference counts for first and second are both incremented in the constructor,
and decremented in the destructor.
*/
- static SkSumPathEffect* Create(SkPathEffect* first, SkPathEffect* second) {
+ static SkPathEffect* Create(SkPathEffect* first, SkPathEffect* second) {
+ if (!first) {
+ return SkSafeRef(second);
+ }
+ if (!second) {
+ return SkSafeRef(first);
+ }
return new SkSumPathEffect(first, second);
}
diff --git a/include/effects/Sk1DPathEffect.h b/include/effects/Sk1DPathEffect.h
index 3419dc23b7..03c6966943 100644
--- a/include/effects/Sk1DPathEffect.h
+++ b/include/effects/Sk1DPathEffect.h
@@ -46,7 +46,7 @@ public:
kRotate_Style, // rotate the shape about its center
kMorph_Style, // transform each point, and turn lines into curves
- kStyleCount
+ kLastEnum_Style = kMorph_Style,
};
/** Dash by replicating the specified path.
@@ -56,9 +56,7 @@ public:
@param style how to transform path at each point (based on the current
position and tangent)
*/
- static SkPathEffect* Create(const SkPath& path, SkScalar advance, SkScalar phase, Style style) {
- return new SkPath1DPathEffect(path, advance, phase, style);
- }
+ static SkPathEffect* Create(const SkPath& path, SkScalar advance, SkScalar phase, Style);
virtual bool filterPath(SkPath*, const SkPath&,
SkStrokeRec*, const SkRect*) const override;
diff --git a/include/effects/SkAlphaThresholdFilter.h b/include/effects/SkAlphaThresholdFilter.h
index 17521b6455..033e8d1e54 100644
--- a/include/effects/SkAlphaThresholdFilter.h
+++ b/include/effects/SkAlphaThresholdFilter.h
@@ -20,8 +20,8 @@ public:
* The 0,0 point of the region corresponds to the upper left corner of the
* source image.
*/
- static SkImageFilter* Create(const SkRegion& region, SkScalar innerThreshold,
- SkScalar outerThreshold, SkImageFilter* input = NULL);
+ static SkImageFilter* Create(const SkRegion& region, SkScalar innerMin,
+ SkScalar outerMax, SkImageFilter* input = NULL);
SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP();
};
diff --git a/include/effects/SkDashPathEffect.h b/include/effects/SkDashPathEffect.h
index 3c1407b725..08b0a4693f 100644
--- a/include/effects/SkDashPathEffect.h
+++ b/include/effects/SkDashPathEffect.h
@@ -36,10 +36,7 @@ public:
Note: only affects stroked paths.
*/
- static SkPathEffect* Create(const SkScalar intervals[], int count, SkScalar phase) {
- return new SkDashPathEffect(intervals, count, phase);
- }
- virtual ~SkDashPathEffect();
+ static SkPathEffect* Create(const SkScalar intervals[], int count, SkScalar phase);
virtual bool filterPath(SkPath* dst, const SkPath& src,
SkStrokeRec*, const SkRect*) const override;
@@ -58,6 +55,7 @@ public:
#endif
protected:
+ virtual ~SkDashPathEffect();
SkDashPathEffect(const SkScalar intervals[], int count, SkScalar phase);
void flatten(SkWriteBuffer&) const override;
@@ -66,6 +64,7 @@ private:
int32_t fCount;
SkScalar fPhase;
// computed from phase
+
SkScalar fInitialDashLength;
int32_t fInitialDashIndex;
SkScalar fIntervalLength;
diff --git a/samplecode/SampleFilterFuzz.cpp b/samplecode/SampleFilterFuzz.cpp
index f8ceed452c..687921ae0b 100644
--- a/samplecode/SampleFilterFuzz.cpp
+++ b/samplecode/SampleFilterFuzz.cpp
@@ -204,7 +204,7 @@ static SkTypeface::Style make_typeface_style() {
}
static SkPath1DPathEffect::Style make_path_1d_path_effect_style() {
- return static_cast<SkPath1DPathEffect::Style>(R(SkPath1DPathEffect::kStyleCount));
+ return static_cast<SkPath1DPathEffect::Style>(R((int)SkPath1DPathEffect::kLastEnum_Style + 1));
}
static SkColor make_color() {
@@ -527,9 +527,14 @@ static SkPaint make_paint() {
paint.setXfermodeMode(make_xfermode());
paint.setPathEffect(make_path_effect());
paint.setMaskFilter(make_mask_filter());
- SkAutoTUnref<SkTypeface> typeface(
- SkTypeface::CreateFromName(make_font_name().c_str(), make_typeface_style()));
- paint.setTypeface(typeface);
+
+ if (false) {
+ // our validating buffer does not support typefaces yet, so skip this for now
+ SkAutoTUnref<SkTypeface> typeface(
+ SkTypeface::CreateFromName(make_font_name().c_str(), make_typeface_style()));
+ paint.setTypeface(typeface);
+ }
+
SkLayerRasterizer::Builder rasterizerBuilder;
SkPaint paintForRasterizer;
if (R(2) == 1) {
diff --git a/src/effects/Sk1DPathEffect.cpp b/src/effects/Sk1DPathEffect.cpp
index 041886e1db..4be6f975d3 100644
--- a/src/effects/Sk1DPathEffect.cpp
+++ b/src/effects/Sk1DPathEffect.cpp
@@ -35,39 +35,33 @@ bool Sk1DPathEffect::filterPath(SkPath* dst, const SkPath& src,
SkPath1DPathEffect::SkPath1DPathEffect(const SkPath& path, SkScalar advance,
SkScalar phase, Style style) : fPath(path)
{
- if (advance <= 0 || path.isEmpty()) {
- SkDEBUGF(("SkPath1DPathEffect can't use advance <= 0\n"));
- fAdvance = 0; // signals we can't draw anything
- fInitialOffset = 0;
- fStyle = kStyleCount;
- } else {
- // cleanup their phase parameter, inverting it so that it becomes an
- // offset along the path (to match the interpretation in PostScript)
- if (phase < 0) {
- phase = -phase;
- if (phase > advance) {
- phase = SkScalarMod(phase, advance);
- }
- } else {
- if (phase > advance) {
- phase = SkScalarMod(phase, advance);
- }
- phase = advance - phase;
+ SkASSERT(advance > 0 && !path.isEmpty());
+ // cleanup their phase parameter, inverting it so that it becomes an
+ // offset along the path (to match the interpretation in PostScript)
+ if (phase < 0) {
+ phase = -phase;
+ if (phase > advance) {
+ phase = SkScalarMod(phase, advance);
}
- // now catch the edge case where phase == advance (within epsilon)
- if (phase >= advance) {
- phase = 0;
+ } else {
+ if (phase > advance) {
+ phase = SkScalarMod(phase, advance);
}
- SkASSERT(phase >= 0);
+ phase = advance - phase;
+ }
+ // now catch the edge case where phase == advance (within epsilon)
+ if (phase >= advance) {
+ phase = 0;
+ }
+ SkASSERT(phase >= 0);
- fAdvance = advance;
- fInitialOffset = phase;
+ fAdvance = advance;
+ fInitialOffset = phase;
- if ((unsigned)style >= kStyleCount) {
- SkDEBUGF(("SkPath1DPathEffect style enum out of range %d\n", style));
- }
- fStyle = style;
+ if ((unsigned)style > kMorph_Style) {
+ SkDEBUGF(("SkPath1DPathEffect style enum out of range %d\n", style));
}
+ fStyle = style;
}
bool SkPath1DPathEffect::filterPath(SkPath* dst, const SkPath& src,
@@ -207,3 +201,13 @@ void SkPath1DPathEffect::toString(SkString* str) const {
str->appendf(")");
}
#endif
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+SkPathEffect* SkPath1DPathEffect::Create(const SkPath& path, SkScalar advance, SkScalar phase,
+ Style style) {
+ if (advance <= 0 || path.isEmpty()) {
+ return nullptr;
+ }
+ return new SkPath1DPathEffect(path, advance, phase, style);
+}
diff --git a/src/effects/SkAlphaThresholdFilter.cpp b/src/effects/SkAlphaThresholdFilter.cpp
index 79520602b7..d3d36f7630 100644
--- a/src/effects/SkAlphaThresholdFilter.cpp
+++ b/src/effects/SkAlphaThresholdFilter.cpp
@@ -45,11 +45,19 @@ SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkAlphaThresholdFilter)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkAlphaThresholdFilterImpl)
SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
+static SkScalar pin_0_1(SkScalar x) {
+ return SkMinScalar(SkMaxScalar(x, 0), 1);
+}
SkImageFilter* SkAlphaThresholdFilter::Create(const SkRegion& region,
SkScalar innerThreshold,
SkScalar outerThreshold,
SkImageFilter* input) {
+ innerThreshold = pin_0_1(innerThreshold);
+ outerThreshold = pin_0_1(outerThreshold);
+ if (!SkScalarIsFinite(innerThreshold) || !SkScalarIsFinite(outerThreshold)) {
+ return nullptr;
+ }
return new SkAlphaThresholdFilterImpl(region, innerThreshold, outerThreshold, input);
}
@@ -334,7 +342,6 @@ void SkAlphaThresholdFilterImpl::flatten(SkWriteBuffer& buffer) const {
bool SkAlphaThresholdFilterImpl::onFilterImageDeprecated(Proxy* proxy, const SkBitmap& src,
const Context& ctx, SkBitmap* dst,
SkIPoint* offset) const {
- SkASSERT(src.colorType() == kN32_SkColorType);
if (src.colorType() != kN32_SkColorType) {
return false;
diff --git a/src/effects/SkDashPathEffect.cpp b/src/effects/SkDashPathEffect.cpp
index 6e10e5466d..ced0aab69a 100644
--- a/src/effects/SkDashPathEffect.cpp
+++ b/src/effects/SkDashPathEffect.cpp
@@ -384,3 +384,17 @@ void SkDashPathEffect::toString(SkString* str) const {
str->appendf("))");
}
#endif
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+SkPathEffect* SkDashPathEffect::Create(const SkScalar intervals[], int count, SkScalar phase) {
+ if ((count < 2) || !SkIsAlign2(count)) {
+ return nullptr;
+ }
+ for (int i = 0; i < count; i++) {
+ if (intervals[i] < 0) {
+ return nullptr;
+ }
+ }
+ return new SkDashPathEffect(intervals, count, phase);
+}