Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Unified Diff: src/effects/SkPerlinNoiseShader.cpp

Issue 83343003: Adding more validation (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Fixed comments Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/effects/SkOffsetImageFilter.cpp ('k') | src/effects/SkRectShaderImageFilter.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/effects/SkPerlinNoiseShader.cpp
diff --git a/src/effects/SkPerlinNoiseShader.cpp b/src/effects/SkPerlinNoiseShader.cpp
index f2ce67924e5d4109800cfafc6b490f8868caf950..62f4f2087d883371e34b8bd31e7b9678c631d30f 100644
--- a/src/effects/SkPerlinNoiseShader.cpp
+++ b/src/effects/SkPerlinNoiseShader.cpp
@@ -51,6 +51,11 @@ inline SkScalar smoothCurve(SkScalar t) {
return SkScalarMul(SkScalarSquare(t), SK_Scalar3 - 2 * t);
}
+bool perlin_noise_type_is_valid(SkPerlinNoiseShader::Type type) {
+ return (SkPerlinNoiseShader::kFractalNoise_Type == type) ||
+ (SkPerlinNoiseShader::kTurbulence_Type == type);
+}
+
} // end namespace
struct SkPerlinNoiseShader::StitchData {
@@ -279,7 +284,7 @@ SkPerlinNoiseShader::SkPerlinNoiseShader(SkPerlinNoiseShader::Type type,
: fType(type)
, fBaseFrequencyX(baseFrequencyX)
, fBaseFrequencyY(baseFrequencyY)
- , fNumOctaves(numOctaves & 0xFF /*[0,255] octaves allowed*/)
+ , fNumOctaves(numOctaves > 255 ? 255 : numOctaves/*[0,255] octaves allowed*/)
, fSeed(seed)
, fStitchTiles((tileSize != NULL) && !tileSize->isEmpty())
, fPaintingData(NULL)
@@ -301,6 +306,8 @@ SkPerlinNoiseShader::SkPerlinNoiseShader(SkFlattenableReadBuffer& buffer) :
fTileSize.fHeight = buffer.readInt();
setTileSize(fTileSize);
fMatrix.reset();
+ buffer.validate(perlin_noise_type_is_valid(fType) &&
+ (fNumOctaves >= 0) && (fNumOctaves <= 255));
}
SkPerlinNoiseShader::~SkPerlinNoiseShader() {
« no previous file with comments | « src/effects/SkOffsetImageFilter.cpp ('k') | src/effects/SkRectShaderImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698