Fix Perlin noise fuzz issue
authorrobertphillips <robertphillips@google.com>
Mon, 27 Jun 2016 19:26:29 +0000 (12:26 -0700)
committerCommit bot <commit-bot@chromium.org>
Mon, 27 Jun 2016 19:26:29 +0000 (12:26 -0700)
The main "fix" here was that the assert was checking the un-clamped input value rather than the clamped value.

The SkValidatingReadBuffer.cpp change was required to get the reproducing fuzz test case to complete.

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2107453002

Review-Url: https://codereview.chromium.org/2107453002

src/core/SkValidatingReadBuffer.cpp
src/effects/SkPerlinNoiseShader.cpp

index 277951688945d1a83969b168d1d50c8ba2ead766..2dd70706db079b6ea23dba98017915080efb1ab9 100644 (file)
@@ -248,7 +248,9 @@ SkFlattenable* SkValidatingReadBuffer::readFlattenable(SkFlattenable::Type type)
         }
 
         SkString* namePtr = fFlattenableDict.find(index);
-        SkASSERT(namePtr);
+        if (!namePtr) {
+            return nullptr;
+        }
         name = *namePtr;
     }
 
index 1400905bfe61d42c26839599bb8af4faa8d3939f..2268d4e1d5ed31d904eabd656aa8b0059d920585 100644 (file)
@@ -275,12 +275,12 @@ SkPerlinNoiseShader::SkPerlinNoiseShader(SkPerlinNoiseShader::Type type,
   : fType(type)
   , fBaseFrequencyX(baseFrequencyX)
   , fBaseFrequencyY(baseFrequencyY)
-  , fNumOctaves(numOctaves > 255 ? 255 : numOctaves/*[0,255] octaves allowed*/)
+  , fNumOctaves(SkTPin<int>(numOctaves, 0, 255)) // [0,255] octaves allowed
   , fSeed(seed)
   , fTileSize(nullptr == tileSize ? SkISize::Make(0, 0) : *tileSize)
   , fStitchTiles(!fTileSize.isEmpty())
 {
-    SkASSERT(numOctaves >= 0 && numOctaves < 256);
+    SkASSERT(fNumOctaves >= 0 && fNumOctaves < 256);
 }
 
 SkPerlinNoiseShader::~SkPerlinNoiseShader() {