Reland of ix misc asserts and checks found by fuzzer (patchset #1 id:1 of https:...
authorreed <reed@google.com>
Mon, 22 Feb 2016 13:54:53 +0000 (05:54 -0800)
committerCommit bot <commit-bot@chromium.org>
Mon, 22 Feb 2016 13:54:53 +0000 (05:54 -0800)
Reason for revert:
deps instability seemingly fixed. trying again.

Original issue's description:
> Revert of fix misc asserts and checks found by fuzzer (patchset #1 id:1 of https://codereview.chromium.org/1713383002/ )
>
> Reason for revert:
> speculative deps-roll fix
>
> Original issue's description:
> > fix misc asserts and checks found by fuzzer
> >
> > BUG=skia:
> > GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1713383002
> >
> > TBR=robertphilips
> >
> > Committed: https://skia.googlesource.com/skia/+/00bea4ad310c4ec4dd95809b47ce3fbfa8fd0e1e
>
> TBR=robertphillips@google.com
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=skia:
>
> Committed: https://skia.googlesource.com/skia/+/d98ef6377269e3596423225ab922301ed40529a0

TBR=robertphillips@google.com
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:

Review URL: https://codereview.chromium.org/1723473002

include/core/SkPathEffect.h
include/effects/Sk1DPathEffect.h
include/effects/SkDashPathEffect.h
samplecode/SampleFilterFuzz.cpp
src/core/SkCanvas.cpp
src/effects/Sk1DPathEffect.cpp
src/effects/SkAlphaThresholdFilter.cpp
src/effects/SkDashPathEffect.cpp

index bd68c8f..a77b946 100644 (file)
@@ -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);
     }
 
index 3419dc2..c832888 100644 (file)
@@ -45,8 +45,6 @@ public:
         kTranslate_Style,   // translate the shape to each position
         kRotate_Style,      // rotate the shape about its center
         kMorph_Style,       // transform each point, and turn lines into curves
-
-        kStyleCount
     };
 
     /** Dash by replicating the specified path.
@@ -56,9 +54,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;
index 3c1407b..08b0a46 100644 (file)
@@ -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;
index f8ceed4..45b43df 100644 (file)
@@ -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::kMorph_Style + 1));
 }
 
 static SkColor make_color() {
@@ -529,7 +529,9 @@ static SkPaint make_paint() {
     paint.setMaskFilter(make_mask_filter());
     SkAutoTUnref<SkTypeface> typeface(
         SkTypeface::CreateFromName(make_font_name().c_str(), make_typeface_style()));
+#if 0
     paint.setTypeface(typeface);
+#endif
     SkLayerRasterizer::Builder rasterizerBuilder;
     SkPaint paintForRasterizer;
     if (R(2) == 1) {
index 653f4b1..aa3261d 100644 (file)
@@ -1072,11 +1072,14 @@ bool SkCanvas::clipRectBounds(const SkRect* bounds, SaveLayerFlags saveLayerFlag
     if (!this->getClipDeviceBounds(&clipBounds)) {
         return false;
     }
+    SkASSERT(!clipBounds.isEmpty());
 
     const SkMatrix& ctm = fMCRec->fMatrix;  // this->getTotalMatrix()
 
     if (imageFilter) {
-        imageFilter->filterBounds(clipBounds, ctm, &clipBounds);
+        if (!imageFilter->filterBounds(clipBounds, ctm, &clipBounds) || clipBounds.isEmpty()) {
+            return false;
+        }
         if (bounds && !imageFilter->canComputeFastBounds()) {
             bounds = nullptr;
         }
@@ -1778,6 +1781,7 @@ bool SkCanvas::getClipDeviceBounds(SkIRect* bounds) const {
         return false;
     }
 
+    SkASSERT(!clip.getBounds().isEmpty());
     if (bounds) {
         *bounds = clip.getBounds();
     }
index 041886e..4be6f97 100644 (file)
@@ -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);
+}
index 7952060..4067970 100644 (file)
@@ -45,11 +45,19 @@ SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkAlphaThresholdFilter)
     SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkAlphaThresholdFilterImpl)
 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
 
+static bool outside_unit(SkScalar x) {
+    return x < 0 || x > 1;
+}
 
 SkImageFilter* SkAlphaThresholdFilter::Create(const SkRegion& region,
                                               SkScalar innerThreshold,
                                               SkScalar outerThreshold,
                                               SkImageFilter* input) {
+    if (outside_unit(innerThreshold) || outside_unit(outerThreshold) ||
+        innerThreshold > 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;
index 6e10e54..ced0aab 100644 (file)
@@ -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);
+}