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

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: Added dox in SkFlattenableBuffers.h 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 unified diff | Download patch | Annotate | Revision Log
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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 } 143 }
144 144
145 void SkValidatingReadBuffer::readPath(SkPath* path) { 145 void SkValidatingReadBuffer::readPath(SkPath* path) {
146 const size_t size = path->readFromMemory(fReader.peek()); 146 const size_t size = path->readFromMemory(fReader.peek());
147 fError = fError || (SkAlign4(size) != size); 147 fError = fError || (SkAlign4(size) != size);
148 if (!fError) { 148 if (!fError) {
149 (void)this->skip(size); 149 (void)this->skip(size);
150 } 150 }
151 } 151 }
152 152
153 uint32_t SkValidatingReadBuffer::readByteArray(void* value) { 153 uint32_t SkValidatingReadBuffer::readByteArray(void* value, uint32_t size) {
154 const uint32_t length = this->readUInt(); 154 const uint32_t length = this->readUInt();
155 fError = fError || (size != length);
155 const void* ptr = this->skip(SkAlign4(length)); 156 const void* ptr = this->skip(SkAlign4(length));
156 if (!fError) { 157 if (!fError) {
157 memcpy(value, ptr, length); 158 memcpy(value, ptr, length);
158 return length; 159 return length;
159 } 160 }
160 return 0; 161 return 0;
161 } 162 }
162 163
163 uint32_t SkValidatingReadBuffer::readColorArray(SkColor* colors) { 164 uint32_t SkValidatingReadBuffer::readColorArray(SkColor* colors, uint32_t size) {
164 const uint32_t count = this->readUInt(); 165 const uint32_t count = this->readUInt();
165 const uint32_t byteLength = count * sizeof(SkColor); 166 const uint32_t byteLength = count * sizeof(SkColor);
167 fError = fError || (size != byteLength);
166 const void* ptr = this->skip(SkAlign4(byteLength)); 168 const void* ptr = this->skip(SkAlign4(byteLength));
167 if (!fError) { 169 if (!fError) {
168 memcpy(colors, ptr, byteLength); 170 memcpy(colors, ptr, byteLength);
169 return count; 171 return count;
170 } 172 }
171 return 0; 173 return 0;
172 } 174 }
173 175
174 uint32_t SkValidatingReadBuffer::readIntArray(int32_t* values) { 176 uint32_t SkValidatingReadBuffer::readIntArray(int32_t* values, uint32_t size) {
175 const uint32_t count = this->readUInt(); 177 const uint32_t count = this->readUInt();
176 const uint32_t byteLength = count * sizeof(int32_t); 178 const uint32_t byteLength = count * sizeof(int32_t);
179 fError = fError || (size != byteLength);
177 const void* ptr = this->skip(SkAlign4(byteLength)); 180 const void* ptr = this->skip(SkAlign4(byteLength));
178 if (!fError) { 181 if (!fError) {
179 memcpy(values, ptr, byteLength); 182 memcpy(values, ptr, byteLength);
180 return count; 183 return count;
181 } 184 }
182 return 0; 185 return 0;
183 } 186 }
184 187
185 uint32_t SkValidatingReadBuffer::readPointArray(SkPoint* points) { 188 uint32_t SkValidatingReadBuffer::readPointArray(SkPoint* points, uint32_t size) {
186 const uint32_t count = this->readUInt(); 189 const uint32_t count = this->readUInt();
187 const uint32_t byteLength = count * sizeof(SkPoint); 190 const uint32_t byteLength = count * sizeof(SkPoint);
191 fError = fError || (size != byteLength);
188 const void* ptr = this->skip(SkAlign4(byteLength)); 192 const void* ptr = this->skip(SkAlign4(byteLength));
189 if (!fError) { 193 if (!fError) {
190 memcpy(points, ptr, byteLength); 194 memcpy(points, ptr, byteLength);
191 return count; 195 return count;
192 } 196 }
193 return 0; 197 return 0;
194 } 198 }
195 199
196 uint32_t SkValidatingReadBuffer::readScalarArray(SkScalar* values) { 200 uint32_t SkValidatingReadBuffer::readScalarArray(SkScalar* values, uint32_t size ) {
197 const uint32_t count = this->readUInt(); 201 const uint32_t count = this->readUInt();
198 const uint32_t byteLength = count * sizeof(SkScalar); 202 const uint32_t byteLength = count * sizeof(SkScalar);
203 fError = fError || (size != byteLength);
199 const void* ptr = this->skip(SkAlign4(byteLength)); 204 const void* ptr = this->skip(SkAlign4(byteLength));
200 if (!fError) { 205 if (!fError) {
201 memcpy(values, ptr, byteLength); 206 memcpy(values, ptr, byteLength);
202 return count; 207 return count;
203 } 208 }
204 return 0; 209 return 0;
205 } 210 }
206 211
207 uint32_t SkValidatingReadBuffer::getArrayCount() { 212 uint32_t SkValidatingReadBuffer::getArrayCount() {
208 return *(uint32_t*)fReader.peek(); 213 return *(uint32_t*)fReader.peek();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 delete obj; 260 delete obj;
256 obj = NULL; 261 obj = NULL;
257 } 262 }
258 } else { 263 } else {
259 // we must skip the remaining data 264 // we must skip the remaining data
260 this->skip(sizeRecorded); 265 this->skip(sizeRecorded);
261 SkASSERT(false); 266 SkASSERT(false);
262 } 267 }
263 return obj; 268 return obj;
264 } 269 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698