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

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

Issue 1308273011: Handle zero-length encoded images gracefully during deserialization (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: generator comments Created 5 years, 3 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
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "SkWriteBuffer.h" 9 #include "SkWriteBuffer.h"
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 216
217 this->writeUInt(0); // signal raw pixels 217 this->writeUInt(0); // signal raw pixels
218 SkBitmap::WriteRawPixels(this, bitmap); 218 SkBitmap::WriteRawPixels(this, bitmap);
219 } 219 }
220 220
221 void SkWriteBuffer::writeImage(const SkImage* image) { 221 void SkWriteBuffer::writeImage(const SkImage* image) {
222 this->writeInt(image->width()); 222 this->writeInt(image->width());
223 this->writeInt(image->height()); 223 this->writeInt(image->height());
224 224
225 SkAutoTUnref<SkData> encoded(image->encode(this->getPixelSerializer())); 225 SkAutoTUnref<SkData> encoded(image->encode(this->getPixelSerializer()));
226 if (encoded) { 226 if (encoded && encoded->size() > 0) {
227 write_encoded_bitmap(this, encoded, SkIPoint::Make(0, 0)); 227 write_encoded_bitmap(this, encoded, SkIPoint::Make(0, 0));
228 return; 228 return;
229 } 229 }
230 230
231 this->writeUInt(0); // signal no pixels (in place of the size of the encoded data) 231 this->writeUInt(0); // signal no pixels (in place of the size of the encoded data)
232 } 232 }
233 233
234 void SkWriteBuffer::writeTypeface(SkTypeface* obj) { 234 void SkWriteBuffer::writeTypeface(SkTypeface* obj) {
235 if (nullptr == obj || nullptr == fTFSet) { 235 if (nullptr == obj || nullptr == fTFSet) {
236 fWriter.write32(0); 236 fWriter.write32(0);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 // make room for the size of the flattened object 334 // make room for the size of the flattened object
335 (void)fWriter.reserve(sizeof(uint32_t)); 335 (void)fWriter.reserve(sizeof(uint32_t));
336 // record the current size, so we can subtract after the object writes. 336 // record the current size, so we can subtract after the object writes.
337 size_t offset = fWriter.bytesWritten(); 337 size_t offset = fWriter.bytesWritten();
338 // now flatten the object 338 // now flatten the object
339 flattenable->flatten(*this); 339 flattenable->flatten(*this);
340 size_t objSize = fWriter.bytesWritten() - offset; 340 size_t objSize = fWriter.bytesWritten() - offset;
341 // record the obj's size 341 // record the obj's size
342 fWriter.overwriteTAt(offset - sizeof(uint32_t), SkToU32(objSize)); 342 fWriter.overwriteTAt(offset - sizeof(uint32_t), SkToU32(objSize));
343 } 343 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698