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

Side by Side Diff: src/effects/SkMergeImageFilter.cpp

Issue 83343003: Adding more validation (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Fixed comments Created 7 years 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
« no previous file with comments | « src/effects/SkMatrixConvolutionImageFilter.cpp ('k') | src/effects/SkMorphologyImageFilter.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "SkMergeImageFilter.h" 8 #include "SkMergeImageFilter.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkDevice.h" 10 #include "SkDevice.h"
11 #include "SkFlattenableBuffers.h" 11 #include "SkFlattenableBuffers.h"
12 #include "SkValidationUtils.h" 12 #include "SkValidationUtils.h"
13 13
14 // Use 65535 as an arbitrary large number of inputs that this image filter shoul d never overflow
15 static const int kMaxInputs = 65535;
16
14 /////////////////////////////////////////////////////////////////////////////// 17 ///////////////////////////////////////////////////////////////////////////////
15 18
16 void SkMergeImageFilter::initAllocModes() { 19 void SkMergeImageFilter::initAllocModes() {
17 int inputCount = countInputs(); 20 int inputCount = countInputs();
18 if (inputCount) { 21 if (inputCount) {
19 size_t size = sizeof(uint8_t) * inputCount; 22 size_t size = sizeof(uint8_t) * inputCount;
20 if (size <= sizeof(fStorage)) { 23 if (size <= sizeof(fStorage)) {
21 fModes = SkTCast<uint8_t*>(fStorage); 24 fModes = SkTCast<uint8_t*>(fStorage);
22 } else { 25 } else {
23 fModes = SkTCast<uint8_t*>(sk_malloc_throw(size)); 26 fModes = SkTCast<uint8_t*>(sk_malloc_throw(size));
(...skipping 22 matching lines...) Expand all
46 SkXfermode::Mode modes[] = { mode, mode }; 49 SkXfermode::Mode modes[] = { mode, mode };
47 this->initModes(modes); 50 this->initModes(modes);
48 } else { 51 } else {
49 fModes = NULL; 52 fModes = NULL;
50 } 53 }
51 } 54 }
52 55
53 SkMergeImageFilter::SkMergeImageFilter(SkImageFilter* filters[], int count, 56 SkMergeImageFilter::SkMergeImageFilter(SkImageFilter* filters[], int count,
54 const SkXfermode::Mode modes[], 57 const SkXfermode::Mode modes[],
55 const CropRect* cropRect) : INHERITED(cou nt, filters, cropRect) { 58 const CropRect* cropRect) : INHERITED(cou nt, filters, cropRect) {
59 SkASSERT(count <= kMaxInputs);
56 this->initModes(modes); 60 this->initModes(modes);
57 } 61 }
58 62
59 SkMergeImageFilter::~SkMergeImageFilter() { 63 SkMergeImageFilter::~SkMergeImageFilter() {
60 64
61 if (fModes != SkTCast<uint8_t*>(fStorage)) { 65 if (fModes != SkTCast<uint8_t*>(fStorage)) {
62 sk_free(fModes); 66 sk_free(fModes);
63 } 67 }
64 } 68 }
65 69
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 153
150 void SkMergeImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { 154 void SkMergeImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const {
151 this->INHERITED::flatten(buffer); 155 this->INHERITED::flatten(buffer);
152 156
153 buffer.writeBool(fModes != NULL); 157 buffer.writeBool(fModes != NULL);
154 if (fModes) { 158 if (fModes) {
155 buffer.writeByteArray(fModes, countInputs() * sizeof(fModes[0])); 159 buffer.writeByteArray(fModes, countInputs() * sizeof(fModes[0]));
156 } 160 }
157 } 161 }
158 162
159 SkMergeImageFilter::SkMergeImageFilter(SkFlattenableReadBuffer& buffer) : INHERI TED(buffer) { 163 SkMergeImageFilter::SkMergeImageFilter(SkFlattenableReadBuffer& buffer)
164 : INHERITED(kMaxInputs, buffer) {
160 bool hasModes = buffer.readBool(); 165 bool hasModes = buffer.readBool();
161 if (hasModes) { 166 if (hasModes) {
162 this->initAllocModes(); 167 this->initAllocModes();
163 int nbInputs = countInputs(); 168 int nbInputs = countInputs();
164 size_t size = nbInputs * sizeof(fModes[0]); 169 size_t size = nbInputs * sizeof(fModes[0]);
165 SkASSERT(buffer.getArrayCount() == size); 170 SkASSERT(buffer.getArrayCount() == size);
166 buffer.readByteArray(fModes, size); 171 buffer.readByteArray(fModes, size);
167 for (int i = 0; i < nbInputs; ++i) { 172 for (int i = 0; i < nbInputs; ++i) {
168 buffer.validate(SkIsValidMode((SkXfermode::Mode)fModes[i])); 173 buffer.validate(SkIsValidMode((SkXfermode::Mode)fModes[i]));
169 } 174 }
170 } else { 175 } else {
171 fModes = 0; 176 fModes = 0;
172 } 177 }
173 } 178 }
OLDNEW
« no previous file with comments | « src/effects/SkMatrixConvolutionImageFilter.cpp ('k') | src/effects/SkMorphologyImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698