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

Side by Side Diff: src/core/SkValidatingReadBuffer.cpp

Issue 37803002: Adding size parameter to read array functions (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: More uint32_t to size_t changes 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
« no previous file with comments | « src/core/SkValidatingReadBuffer.h ('k') | src/effects/SkBicubicImageFilter.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 2013 Google Inc. 2 * Copyright 2013 Google Inc.
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 "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkErrorInternals.h" 9 #include "SkErrorInternals.h"
10 #include "SkValidatingReadBuffer.h" 10 #include "SkValidatingReadBuffer.h"
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 } 142 }
143 143
144 void SkValidatingReadBuffer::readPath(SkPath* path) { 144 void SkValidatingReadBuffer::readPath(SkPath* path) {
145 const size_t size = path->readFromMemory(fReader.peek()); 145 const size_t size = path->readFromMemory(fReader.peek());
146 fError = fError || (SkAlign4(size) != size); 146 fError = fError || (SkAlign4(size) != size);
147 if (!fError) { 147 if (!fError) {
148 (void)this->skip(size); 148 (void)this->skip(size);
149 } 149 }
150 } 150 }
151 151
152 uint32_t SkValidatingReadBuffer::readByteArray(void* value) { 152 bool SkValidatingReadBuffer::readByteArray(void* value, size_t size) {
153 const uint32_t length = this->readUInt(); 153 const uint32_t length = this->getArrayCount();
154 fError = fError || (size != length);
155 (void)this->skip(sizeof(uint32_t)); // Skip array count
sugoi1 2013/10/30 18:14:32 Here, the reason why I changed readUInt() for : 1
154 const void* ptr = this->skip(SkAlign4(length)); 156 const void* ptr = this->skip(SkAlign4(length));
155 if (!fError) { 157 if (!fError) {
156 memcpy(value, ptr, length); 158 memcpy(value, ptr, length);
157 return length; 159 return true;
158 } 160 }
159 return 0; 161 return false;
160 } 162 }
161 163
162 uint32_t SkValidatingReadBuffer::readColorArray(SkColor* colors) { 164 bool SkValidatingReadBuffer::readColorArray(SkColor* colors, size_t size) {
163 const uint32_t count = this->readUInt(); 165 const uint32_t count = this->getArrayCount();
164 const uint32_t byteLength = count * sizeof(SkColor); 166 const size_t byteLength = count * sizeof(SkColor);
167 fError = fError || (size != byteLength);
168 (void)this->skip(sizeof(uint32_t)); // Skip array count
165 const void* ptr = this->skip(SkAlign4(byteLength)); 169 const void* ptr = this->skip(SkAlign4(byteLength));
166 if (!fError) { 170 if (!fError) {
167 memcpy(colors, ptr, byteLength); 171 memcpy(colors, ptr, byteLength);
168 return count; 172 return true;
169 } 173 }
170 return 0; 174 return false;
171 } 175 }
172 176
173 uint32_t SkValidatingReadBuffer::readIntArray(int32_t* values) { 177 bool SkValidatingReadBuffer::readIntArray(int32_t* values, size_t size) {
174 const uint32_t count = this->readUInt(); 178 const uint32_t count = this->getArrayCount();
175 const uint32_t byteLength = count * sizeof(int32_t); 179 const size_t byteLength = count * sizeof(int32_t);
180 fError = fError || (size != byteLength);
181 (void)this->skip(sizeof(uint32_t)); // Skip array count
176 const void* ptr = this->skip(SkAlign4(byteLength)); 182 const void* ptr = this->skip(SkAlign4(byteLength));
177 if (!fError) { 183 if (!fError) {
178 memcpy(values, ptr, byteLength); 184 memcpy(values, ptr, byteLength);
179 return count; 185 return true;
180 } 186 }
181 return 0; 187 return false;
182 } 188 }
183 189
184 uint32_t SkValidatingReadBuffer::readPointArray(SkPoint* points) { 190 bool SkValidatingReadBuffer::readPointArray(SkPoint* points, size_t size) {
185 const uint32_t count = this->readUInt(); 191 const uint32_t count = this->getArrayCount();
186 const uint32_t byteLength = count * sizeof(SkPoint); 192 const size_t byteLength = count * sizeof(SkPoint);
193 fError = fError || (size != byteLength);
194 (void)this->skip(sizeof(uint32_t)); // Skip array count
187 const void* ptr = this->skip(SkAlign4(byteLength)); 195 const void* ptr = this->skip(SkAlign4(byteLength));
188 if (!fError) { 196 if (!fError) {
189 memcpy(points, ptr, byteLength); 197 memcpy(points, ptr, byteLength);
190 return count; 198 return true;
191 } 199 }
192 return 0; 200 return false;
193 } 201 }
194 202
195 uint32_t SkValidatingReadBuffer::readScalarArray(SkScalar* values) { 203 bool SkValidatingReadBuffer::readScalarArray(SkScalar* values, size_t size) {
196 const uint32_t count = this->readUInt(); 204 const uint32_t count = this->getArrayCount();
197 const uint32_t byteLength = count * sizeof(SkScalar); 205 const size_t byteLength = count * sizeof(SkScalar);
206 fError = fError || (size != byteLength);
207 (void)this->skip(sizeof(uint32_t)); // Skip array count
198 const void* ptr = this->skip(SkAlign4(byteLength)); 208 const void* ptr = this->skip(SkAlign4(byteLength));
199 if (!fError) { 209 if (!fError) {
200 memcpy(values, ptr, byteLength); 210 memcpy(values, ptr, byteLength);
201 return count; 211 return true;
202 } 212 }
203 return 0; 213 return false;
204 } 214 }
205 215
206 uint32_t SkValidatingReadBuffer::getArrayCount() { 216 uint32_t SkValidatingReadBuffer::getArrayCount() {
207 return *(uint32_t*)fReader.peek(); 217 return *(uint32_t*)fReader.peek();
208 } 218 }
209 219
210 void SkValidatingReadBuffer::readBitmap(SkBitmap* bitmap) { 220 void SkValidatingReadBuffer::readBitmap(SkBitmap* bitmap) {
211 const int width = this->readInt(); 221 const int width = this->readInt();
212 const int height = this->readInt(); 222 const int height = this->readInt();
213 const size_t length = this->readUInt(); 223 const size_t length = this->readUInt();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 delete obj; 264 delete obj;
255 obj = NULL; 265 obj = NULL;
256 } 266 }
257 } else { 267 } else {
258 // we must skip the remaining data 268 // we must skip the remaining data
259 this->skip(sizeRecorded); 269 this->skip(sizeRecorded);
260 SkASSERT(false); 270 SkASSERT(false);
261 } 271 }
262 return obj; 272 return obj;
263 } 273 }
OLDNEW
« no previous file with comments | « src/core/SkValidatingReadBuffer.h ('k') | src/effects/SkBicubicImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698