OLD | NEW |
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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 bool SkValidatingReadBuffer::readScalarArray(SkScalar* values, size_t size) { | 203 bool SkValidatingReadBuffer::readScalarArray(SkScalar* values, size_t size) { |
204 return readArray(values, size, sizeof(SkScalar)); | 204 return readArray(values, size, sizeof(SkScalar)); |
205 } | 205 } |
206 | 206 |
207 uint32_t SkValidatingReadBuffer::getArrayCount() { | 207 uint32_t SkValidatingReadBuffer::getArrayCount() { |
208 const size_t inc = sizeof(uint32_t); | 208 const size_t inc = sizeof(uint32_t); |
209 fError = fError || !IsPtrAlign4(fReader.peek()) || !fReader.isAvailable(inc)
; | 209 fError = fError || !IsPtrAlign4(fReader.peek()) || !fReader.isAvailable(inc)
; |
210 return fError ? 0 : *(uint32_t*)fReader.peek(); | 210 return fError ? 0 : *(uint32_t*)fReader.peek(); |
211 } | 211 } |
212 | 212 |
213 void SkValidatingReadBuffer::readBitmap(SkBitmap* bitmap) { | |
214 const int width = this->readInt(); | |
215 const int height = this->readInt(); | |
216 const bool useBitmapHeap = this->readBool(); | |
217 const size_t length = this->readUInt(); | |
218 // A size of zero means the SkBitmap was simply flattened. | |
219 if (!this->validate(!useBitmapHeap && (0 == length))) { | |
220 return; | |
221 } | |
222 bitmap->unflatten(*this); | |
223 this->validate((bitmap->width() == width) && (bitmap->height() == height)); | |
224 } | |
225 | |
226 SkTypeface* SkValidatingReadBuffer::readTypeface() { | 213 SkTypeface* SkValidatingReadBuffer::readTypeface() { |
227 // TODO: Implement this (securely) when needed | 214 // TODO: Implement this (securely) when needed |
228 return NULL; | 215 return NULL; |
229 } | 216 } |
230 | 217 |
231 bool SkValidatingReadBuffer::validateAvailable(size_t size) { | 218 bool SkValidatingReadBuffer::validateAvailable(size_t size) { |
232 return this->validate((size <= SK_MaxU32) && fReader.isAvailable(static_cast
<uint32_t>(size))); | 219 return this->validate((size <= SK_MaxU32) && fReader.isAvailable(static_cast
<uint32_t>(size))); |
233 } | 220 } |
234 | 221 |
235 SkFlattenable* SkValidatingReadBuffer::readFlattenable(SkFlattenable::Type type)
{ | 222 SkFlattenable* SkValidatingReadBuffer::readFlattenable(SkFlattenable::Type type)
{ |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 | 263 |
277 void SkValidatingReadBuffer::skipFlattenable() { | 264 void SkValidatingReadBuffer::skipFlattenable() { |
278 SkString name; | 265 SkString name; |
279 this->readString(&name); | 266 this->readString(&name); |
280 if (fError) { | 267 if (fError) { |
281 return; | 268 return; |
282 } | 269 } |
283 uint32_t sizeRecorded = this->readUInt(); | 270 uint32_t sizeRecorded = this->readUInt(); |
284 this->skip(sizeRecorded); | 271 this->skip(sizeRecorded); |
285 } | 272 } |
OLD | NEW |