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

Unified Diff: src/effects/SkMatrixConvolutionImageFilter.cpp

Issue 37803002: Adding size parameter to read array functions (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Fixed comments Created 7 years, 2 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
Index: src/effects/SkMatrixConvolutionImageFilter.cpp
diff --git a/src/effects/SkMatrixConvolutionImageFilter.cpp b/src/effects/SkMatrixConvolutionImageFilter.cpp
index cac30e6a491853ab9907a34cd3df68ba2fa52736..4864aec65aefd60798df0062a82465521bb9f601 100644
--- a/src/effects/SkMatrixConvolutionImageFilter.cpp
+++ b/src/effects/SkMatrixConvolutionImageFilter.cpp
@@ -59,18 +59,20 @@ SkMatrixConvolutionImageFilter::SkMatrixConvolutionImageFilter(
SkMatrixConvolutionImageFilter::SkMatrixConvolutionImageFilter(SkFlattenableReadBuffer& buffer)
: INHERITED(buffer) {
+ // We need to be able to read at most SK_MaxS32 bytes, so divide that
+ // by the size of a scalar to know how many scalars we can read.
+ static const int32_t kMaxSize = SK_MaxS32 / sizeof(SkScalar);
fKernelSize.fWidth = buffer.readInt();
fKernelSize.fHeight = buffer.readInt();
if ((fKernelSize.fWidth >= 1) && (fKernelSize.fHeight >= 1) &&
// Make sure size won't be larger than a signed int,
// which would still be extremely large for a kernel,
// but we don't impose a hard limit for kernel size
- (SK_MaxS32 / fKernelSize.fWidth >= fKernelSize.fHeight)) {
- uint32_t size = fKernelSize.fWidth * fKernelSize.fHeight;
+ (kMaxSize / fKernelSize.fWidth >= fKernelSize.fHeight)) {
+ size_t size = fKernelSize.fWidth * fKernelSize.fHeight;
fKernel = SkNEW_ARRAY(SkScalar, size);
- uint32_t readSize = buffer.readScalarArray(fKernel);
- SkASSERT(readSize == size);
- buffer.validate(readSize == size);
+ SkDEBUGCODE(bool success =) buffer.readScalarArray(fKernel, size);
+ SkASSERT(success);
} else {
fKernel = 0;
}

Powered by Google App Engine
This is Rietveld 408576698