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

Side by Side 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, 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright 2012 The Android Open Source Project 2 * Copyright 2012 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkMatrixConvolutionImageFilter.h" 8 #include "SkMatrixConvolutionImageFilter.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 uint32_t size = fKernelSize.fWidth * fKernelSize.fHeight; 52 uint32_t size = fKernelSize.fWidth * fKernelSize.fHeight;
53 fKernel = SkNEW_ARRAY(SkScalar, size); 53 fKernel = SkNEW_ARRAY(SkScalar, size);
54 memcpy(fKernel, kernel, size * sizeof(SkScalar)); 54 memcpy(fKernel, kernel, size * sizeof(SkScalar));
55 SkASSERT(kernelSize.fWidth >= 1 && kernelSize.fHeight >= 1); 55 SkASSERT(kernelSize.fWidth >= 1 && kernelSize.fHeight >= 1);
56 SkASSERT(target.fX >= 0 && target.fX < kernelSize.fWidth); 56 SkASSERT(target.fX >= 0 && target.fX < kernelSize.fWidth);
57 SkASSERT(target.fY >= 0 && target.fY < kernelSize.fHeight); 57 SkASSERT(target.fY >= 0 && target.fY < kernelSize.fHeight);
58 } 58 }
59 59
60 SkMatrixConvolutionImageFilter::SkMatrixConvolutionImageFilter(SkFlattenableRead Buffer& buffer) 60 SkMatrixConvolutionImageFilter::SkMatrixConvolutionImageFilter(SkFlattenableRead Buffer& buffer)
61 : INHERITED(buffer) { 61 : INHERITED(buffer) {
62 // We need to be able to read at most SK_MaxS32 bytes, so divide that
63 // by the size of a scalar to know how many scalars we can read.
64 static const int32_t kMaxSize = SK_MaxS32 / sizeof(SkScalar);
62 fKernelSize.fWidth = buffer.readInt(); 65 fKernelSize.fWidth = buffer.readInt();
63 fKernelSize.fHeight = buffer.readInt(); 66 fKernelSize.fHeight = buffer.readInt();
64 if ((fKernelSize.fWidth >= 1) && (fKernelSize.fHeight >= 1) && 67 if ((fKernelSize.fWidth >= 1) && (fKernelSize.fHeight >= 1) &&
65 // Make sure size won't be larger than a signed int, 68 // Make sure size won't be larger than a signed int,
66 // which would still be extremely large for a kernel, 69 // which would still be extremely large for a kernel,
67 // but we don't impose a hard limit for kernel size 70 // but we don't impose a hard limit for kernel size
68 (SK_MaxS32 / fKernelSize.fWidth >= fKernelSize.fHeight)) { 71 (kMaxSize / fKernelSize.fWidth >= fKernelSize.fHeight)) {
69 uint32_t size = fKernelSize.fWidth * fKernelSize.fHeight; 72 size_t size = fKernelSize.fWidth * fKernelSize.fHeight;
70 fKernel = SkNEW_ARRAY(SkScalar, size); 73 fKernel = SkNEW_ARRAY(SkScalar, size);
71 uint32_t readSize = buffer.readScalarArray(fKernel); 74 SkDEBUGCODE(bool success =) buffer.readScalarArray(fKernel, size);
72 SkASSERT(readSize == size); 75 SkASSERT(success);
73 buffer.validate(readSize == size);
74 } else { 76 } else {
75 fKernel = 0; 77 fKernel = 0;
76 } 78 }
77 fGain = buffer.readScalar(); 79 fGain = buffer.readScalar();
78 fBias = buffer.readScalar(); 80 fBias = buffer.readScalar();
79 fTarget.fX = buffer.readInt(); 81 fTarget.fX = buffer.readInt();
80 fTarget.fY = buffer.readInt(); 82 fTarget.fY = buffer.readInt();
81 fTileMode = (TileMode) buffer.readInt(); 83 fTileMode = (TileMode) buffer.readInt();
82 fConvolveAlpha = buffer.readBool(); 84 fConvolveAlpha = buffer.readBool();
83 buffer.validate((fKernel != 0) && 85 buffer.validate((fKernel != 0) &&
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 fBias, 657 fBias,
656 fTarget, 658 fTarget,
657 fTileMode, 659 fTileMode,
658 fConvolveAlpha); 660 fConvolveAlpha);
659 return true; 661 return true;
660 } 662 }
661 663
662 /////////////////////////////////////////////////////////////////////////////// 664 ///////////////////////////////////////////////////////////////////////////////
663 665
664 #endif 666 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698