Misc guarding of enums in ImageFilter CreateProcs
Change-Id: I51886aaf2a4670f46ca489b2369dc00e60403c75 Reviewed-on: https://skia-review.googlesource.com/99328 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
parent
548d387ab9
commit
a83d0132ba
@ -21,6 +21,8 @@ struct SkHighContrastConfig {
|
||||
kNoInvert,
|
||||
kInvertBrightness,
|
||||
kInvertLightness,
|
||||
|
||||
kLast = kInvertLightness
|
||||
};
|
||||
|
||||
SkHighContrastConfig() {
|
||||
|
@ -122,6 +122,10 @@ sk_sp<SkFlattenable> SkBlurImageFilterImpl::CreateProc(SkReadBuffer& buffer) {
|
||||
|
||||
static_assert(SkBlurImageFilter::kLast_TileMode == 2, "CreateProc");
|
||||
|
||||
if (!buffer.validate(safe)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return SkBlurImageFilter::Make(
|
||||
sigmaX, sigmaY, common.getInput(0), &common.cropRect(), tileMode);
|
||||
}
|
||||
|
@ -1655,10 +1655,8 @@ size_t SkMatrix::readFromMemory(const void* buffer, size_t length) {
|
||||
if (length < sizeInMemory) {
|
||||
return 0;
|
||||
}
|
||||
if (buffer) {
|
||||
memcpy(fMat, buffer, sizeInMemory);
|
||||
this->setTypeMask(kUnknown_Mask);
|
||||
}
|
||||
memcpy(fMat, buffer, sizeInMemory);
|
||||
this->setTypeMask(kUnknown_Mask);
|
||||
return sizeInMemory;
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "SkColorSpaceXformer.h"
|
||||
#include "SkImageFilterPriv.h"
|
||||
#include "SkReadBuffer.h"
|
||||
#include "SkSafeRange.h"
|
||||
#include "SkSpecialImage.h"
|
||||
#include "SkSpecialSurface.h"
|
||||
#include "SkWriteBuffer.h"
|
||||
@ -33,10 +34,19 @@ sk_sp<SkImageFilter> SkMatrixImageFilter::Make(const SkMatrix& transform,
|
||||
}
|
||||
|
||||
sk_sp<SkFlattenable> SkMatrixImageFilter::CreateProc(SkReadBuffer& buffer) {
|
||||
SkSafeRange safe;
|
||||
|
||||
SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
|
||||
SkMatrix matrix;
|
||||
buffer.readMatrix(&matrix);
|
||||
SkFilterQuality quality = static_cast<SkFilterQuality>(buffer.readInt());
|
||||
|
||||
SkFilterQuality quality = safe.checkLE<SkFilterQuality>(buffer.readInt(),
|
||||
kLast_SkFilterQuality);
|
||||
|
||||
if (!buffer.validate(safe)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return Make(matrix, quality, common.getInput(0));
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "SkGpuBlurUtils.h"
|
||||
#include "SkMaskFilterBase.h"
|
||||
#include "SkReadBuffer.h"
|
||||
#include "SkSafeRange.h"
|
||||
#include "SkWriteBuffer.h"
|
||||
#include "SkMaskFilter.h"
|
||||
#include "SkRRect.h"
|
||||
@ -733,22 +734,21 @@ void SkBlurMaskFilterImpl::computeFastBounds(const SkRect& src,
|
||||
}
|
||||
|
||||
sk_sp<SkFlattenable> SkBlurMaskFilterImpl::CreateProc(SkReadBuffer& buffer) {
|
||||
SkSafeRange safe;
|
||||
|
||||
const SkScalar sigma = buffer.readScalar();
|
||||
const unsigned style = buffer.readUInt();
|
||||
unsigned flags = buffer.readUInt();
|
||||
|
||||
buffer.validate(style <= kLastEnum_SkBlurStyle);
|
||||
buffer.validate(!(flags & ~SkBlurMaskFilter::kAll_BlurFlag));
|
||||
|
||||
flags &= SkBlurMaskFilter::kAll_BlurFlag;
|
||||
SkBlurStyle style = safe.checkLE(buffer.readUInt(), kLastEnum_SkBlurStyle);
|
||||
unsigned flags = safe.checkLE(buffer.readUInt(), SkBlurMaskFilter::kAll_BlurFlag);
|
||||
|
||||
SkRect occluder;
|
||||
buffer.readRect(&occluder);
|
||||
|
||||
if (style <= kLastEnum_SkBlurStyle) {
|
||||
return SkBlurMaskFilter::Make((SkBlurStyle)style, sigma, occluder, flags);
|
||||
if (!buffer.validate(safe)) {
|
||||
return nullptr;
|
||||
}
|
||||
return nullptr;
|
||||
|
||||
return SkBlurMaskFilter::Make((SkBlurStyle)style, sigma, occluder, flags);
|
||||
}
|
||||
|
||||
void SkBlurMaskFilterImpl::flatten(SkWriteBuffer& buffer) const {
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "SkColorSpaceXformer.h"
|
||||
#include "SkImageFilterPriv.h"
|
||||
#include "SkReadBuffer.h"
|
||||
#include "SkSafeRange.h"
|
||||
#include "SkSpecialImage.h"
|
||||
#include "SkSpecialSurface.h"
|
||||
#include "SkWriteBuffer.h"
|
||||
@ -41,13 +42,21 @@ SkDropShadowImageFilter::SkDropShadowImageFilter(SkScalar dx, SkScalar dy,
|
||||
}
|
||||
|
||||
sk_sp<SkFlattenable> SkDropShadowImageFilter::CreateProc(SkReadBuffer& buffer) {
|
||||
SkSafeRange safe;
|
||||
|
||||
SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
|
||||
SkScalar dx = buffer.readScalar();
|
||||
SkScalar dy = buffer.readScalar();
|
||||
SkScalar sigmaX = buffer.readScalar();
|
||||
SkScalar sigmaY = buffer.readScalar();
|
||||
SkColor color = buffer.readColor();
|
||||
ShadowMode shadowMode = static_cast<ShadowMode>(buffer.readInt());
|
||||
|
||||
ShadowMode shadowMode = safe.checkLE<ShadowMode>(buffer.readInt(), kLast_ShadowMode);
|
||||
|
||||
if (!buffer.validate(safe)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return Make(dx, dy, sigmaX, sigmaY, color, shadowMode, common.getInput(0), &common.cropRect());
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "SkPM4f.h"
|
||||
#include "SkArenaAlloc.h"
|
||||
#include "SkRasterPipeline.h"
|
||||
#include "SkSafeRange.h"
|
||||
#include "SkReadBuffer.h"
|
||||
#include "SkString.h"
|
||||
#include "SkWriteBuffer.h"
|
||||
@ -141,10 +142,17 @@ void SkHighContrast_Filter::flatten(SkWriteBuffer& buffer) const {
|
||||
}
|
||||
|
||||
sk_sp<SkFlattenable> SkHighContrast_Filter::CreateProc(SkReadBuffer& buffer) {
|
||||
SkSafeRange safe;
|
||||
|
||||
SkHighContrastConfig config;
|
||||
config.fGrayscale = buffer.readBool();
|
||||
config.fInvertStyle = static_cast<InvertStyle>(buffer.readInt());
|
||||
config.fInvertStyle = safe.checkLE<InvertStyle>(buffer.readInt(), InvertStyle::kLast);
|
||||
config.fContrast = buffer.readScalar();
|
||||
|
||||
if (!buffer.validate(safe)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return SkHighContrastFilter::Make(config);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user