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

Unified Diff: src/effects/gradients/SkGradientShader.cpp

Issue 837013002: improve sanity checks on gradient constructor parameters (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 11 months 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/effects/gradients/SkGradientShader.cpp
diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp
index d50afb763838e7e1e819884094ef2233dbaa1d36..d2b8bc30f858d3244d7076494ab9a2cbbabbe886 100644
--- a/src/effects/gradients/SkGradientShader.cpp
+++ b/src/effects/gradients/SkGradientShader.cpp
@@ -735,6 +735,12 @@ void SkGradientShaderBase::toString(SkString* str) const {
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
+// Return true if these parameters are valid/legal/safe to construct a gradient
+//
+static bool valid_grad(const SkColor colors[], const SkScalar pos[], int count, unsigned tileMode) {
Stephen White 2015/01/06 14:53:30 Nit: pos is unused here (presumably because NULL i
+ return NULL != colors && count >= 1 && tileMode < (unsigned)SkShader::kTileModeCount;
+}
+
// assumes colors is SkColor* and pos is SkScalar*
#define EXPAND_1_COLOR(count) \
SkColor tmp[2]; \
@@ -764,7 +770,10 @@ SkShader* SkGradientShader::CreateLinear(const SkPoint pts[2],
SkShader::TileMode mode,
uint32_t flags,
const SkMatrix* localMatrix) {
- if (NULL == pts || NULL == colors || colorCount < 1) {
+ if (!pts) {
+ return NULL;
+ }
+ if (!valid_grad(colors, pos, colorCount, mode)) {
return NULL;
}
EXPAND_1_COLOR(colorCount);
@@ -780,7 +789,10 @@ SkShader* SkGradientShader::CreateRadial(const SkPoint& center, SkScalar radius,
SkShader::TileMode mode,
uint32_t flags,
const SkMatrix* localMatrix) {
- if (radius <= 0 || NULL == colors || colorCount < 1) {
+ if (radius <= 0) {
+ return NULL;
+ }
+ if (!valid_grad(colors, pos, colorCount, mode)) {
return NULL;
}
EXPAND_1_COLOR(colorCount);
@@ -800,7 +812,10 @@ SkShader* SkGradientShader::CreateTwoPointRadial(const SkPoint& start,
SkShader::TileMode mode,
uint32_t flags,
const SkMatrix* localMatrix) {
- if (startRadius < 0 || endRadius < 0 || NULL == colors || colorCount < 1) {
+ if (startRadius < 0 || endRadius < 0) {
+ return NULL;
+ }
+ if (!valid_grad(colors, pos, colorCount, mode)) {
return NULL;
}
EXPAND_1_COLOR(colorCount);
@@ -821,7 +836,10 @@ SkShader* SkGradientShader::CreateTwoPointConical(const SkPoint& start,
SkShader::TileMode mode,
uint32_t flags,
const SkMatrix* localMatrix) {
- if (startRadius < 0 || endRadius < 0 || NULL == colors || colorCount < 1) {
+ if (startRadius < 0 || endRadius < 0) {
+ return NULL;
+ }
+ if (!valid_grad(colors, pos, colorCount, mode)) {
return NULL;
}
if (start == end && startRadius == endRadius) {
@@ -865,7 +883,7 @@ SkShader* SkGradientShader::CreateSweep(SkScalar cx, SkScalar cy,
int colorCount,
uint32_t flags,
const SkMatrix* localMatrix) {
- if (NULL == colors || colorCount < 1) {
+ if (!valid_grad(colors, pos, colorCount, SkShader::kClamp_TileMode)) {
return NULL;
}
EXPAND_1_COLOR(colorCount);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698