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

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

Issue 718103002: detect bad bitmaps during deserialization (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: return true (but empty) if we just didn't recognize the codec type Created 6 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
« no previous file with comments | « no previous file | src/core/SkReadBuffer.cpp » ('j') | src/core/SkReadBuffer.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 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 #include <new> 7 #include <new>
8 #include "SkBBoxHierarchy.h" 8 #include "SkBBoxHierarchy.h"
9 #include "SkDrawPictureCallback.h" 9 #include "SkDrawPictureCallback.h"
10 #include "SkPictureData.h" 10 #include "SkPictureData.h"
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 fPictureCount = 0; 388 fPictureCount = 0;
389 return false; 389 return false;
390 } 390 }
391 } break; 391 } break;
392 case SK_PICT_BUFFER_SIZE_TAG: { 392 case SK_PICT_BUFFER_SIZE_TAG: {
393 SkAutoMalloc storage(size); 393 SkAutoMalloc storage(size);
394 if (stream->read(storage.get(), size) != size) { 394 if (stream->read(storage.get(), size) != size) {
395 return false; 395 return false;
396 } 396 }
397 397
398 /* Should we use SkValidatingReadBuffer instead? */
scroggo 2014/11/12 18:24:47 If we're going to check isValid, absolutely! Other
398 SkReadBuffer buffer(storage.get(), size); 399 SkReadBuffer buffer(storage.get(), size);
399 buffer.setFlags(pictInfoFlagsToReadBufferFlags(fInfo.fFlags)); 400 buffer.setFlags(pictInfoFlagsToReadBufferFlags(fInfo.fFlags));
400 buffer.setVersion(fInfo.fVersion); 401 buffer.setVersion(fInfo.fVersion);
401 402
402 fFactoryPlayback->setupBuffer(buffer); 403 fFactoryPlayback->setupBuffer(buffer);
403 fTFPlayback.setupBuffer(buffer); 404 fTFPlayback.setupBuffer(buffer);
404 buffer.setBitmapDecoder(proc); 405 buffer.setBitmapDecoder(proc);
405 406
406 while (!buffer.eof()) { 407 while (!buffer.eof() && buffer.isValid()) {
407 tag = buffer.readUInt(); 408 tag = buffer.readUInt();
408 size = buffer.readUInt(); 409 size = buffer.readUInt();
409 if (!this->parseBufferTag(buffer, tag, size)) { 410 if (!this->parseBufferTag(buffer, tag, size)) {
410 return false; 411 return false;
411 } 412 }
412 } 413 }
414 if (!buffer.isValid()) {
scroggo 2014/11/12 18:24:47 Do we need both checks? Is it possible for isVali
415 return false;
416 }
413 SkDEBUGCODE(haveBuffer = true;) 417 SkDEBUGCODE(haveBuffer = true;)
414 } break; 418 } break;
415 } 419 }
416 return true; // success 420 return true; // success
417 } 421 }
418 422
419 bool SkPictureData::parseBufferTag(SkReadBuffer& buffer, 423 bool SkPictureData::parseBufferTag(SkReadBuffer& buffer,
420 uint32_t tag, uint32_t size) { 424 uint32_t tag, uint32_t size) {
421 switch (tag) { 425 switch (tag) {
422 case SK_PICT_BITMAP_BUFFER_TAG: { 426 case SK_PICT_BITMAP_BUFFER_TAG: {
423 const int count = SkToInt(size); 427 const int count = SkToInt(size);
424 fBitmaps = SkTRefArray<SkBitmap>::Create(size); 428 fBitmaps = SkTRefArray<SkBitmap>::Create(size);
425 for (int i = 0; i < count; ++i) { 429 for (int i = 0; i < count; ++i) {
426 SkBitmap* bm = &fBitmaps->writableAt(i); 430 SkBitmap* bm = &fBitmaps->writableAt(i);
427 buffer.readBitmap(bm); 431 if (buffer.readBitmap(bm)) {
428 bm->setImmutable(); 432 bm->setImmutable();
433 } else {
434 return false;
435 }
429 } 436 }
430 } break; 437 } break;
431 case SK_PICT_PAINT_BUFFER_TAG: { 438 case SK_PICT_PAINT_BUFFER_TAG: {
432 const int count = SkToInt(size); 439 const int count = SkToInt(size);
433 fPaints = SkTRefArray<SkPaint>::Create(size); 440 fPaints = SkTRefArray<SkPaint>::Create(size);
434 for (int i = 0; i < count; ++i) { 441 for (int i = 0; i < count; ++i) {
435 buffer.readPaint(&fPaints->writableAt(i)); 442 buffer.readPaint(&fPaints->writableAt(i));
436 } 443 }
437 } break; 444 } break;
438 case SK_PICT_PATH_BUFFER_TAG: 445 case SK_PICT_PATH_BUFFER_TAG:
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 } 589 }
583 } 590 }
584 591
585 bool SkPictureData::suitableForLayerOptimization() const { 592 bool SkPictureData::suitableForLayerOptimization() const {
586 return fContentInfo.numLayers() > 0; 593 return fContentInfo.numLayers() > 0;
587 } 594 }
588 #endif 595 #endif
589 /////////////////////////////////////////////////////////////////////////////// 596 ///////////////////////////////////////////////////////////////////////////////
590 597
591 598
OLDNEW
« no previous file with comments | « no previous file | src/core/SkReadBuffer.cpp » ('j') | src/core/SkReadBuffer.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698