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

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

Issue 23021015: Initial error handling code (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Adding validation helper file Created 7 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 | Annotate | Revision Log
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2008 The Android Open Source Project 3 * Copyright 2008 The Android Open Source Project
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 9
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
11 #include "SkColorPriv.h" 11 #include "SkColorPriv.h"
12 #include "SkDither.h" 12 #include "SkDither.h"
13 #include "SkFlattenable.h" 13 #include "SkFlattenable.h"
14 #include "SkMallocPixelRef.h" 14 #include "SkMallocPixelRef.h"
15 #include "SkMask.h" 15 #include "SkMask.h"
16 #include "SkOrderedReadBuffer.h" 16 #include "SkOrderedReadBuffer.h"
17 #include "SkOrderedWriteBuffer.h" 17 #include "SkOrderedWriteBuffer.h"
18 #include "SkPixelRef.h" 18 #include "SkPixelRef.h"
19 #include "SkThread.h" 19 #include "SkThread.h"
20 #include "SkUnPreMultiply.h" 20 #include "SkUnPreMultiply.h"
21 #include "SkUtils.h" 21 #include "SkUtils.h"
22 #include "SkValidation.h"
22 #include "SkPackBits.h" 23 #include "SkPackBits.h"
23 #include <new> 24 #include <new>
24 25
25 SK_DEFINE_INST_COUNT(SkBitmap::Allocator) 26 SK_DEFINE_INST_COUNT(SkBitmap::Allocator)
26 27
27 static bool isPos32Bits(const Sk64& value) { 28 static bool isPos32Bits(const Sk64& value) {
28 return !value.isNeg() && value.is32(); 29 return !value.isNeg() && value.is32();
29 } 30 }
30 31
31 struct MipLevel { 32 struct MipLevel {
(...skipping 1568 matching lines...) Expand 10 before | Expand all | Expand 10 after
1600 buffer.writeInt(SERIALIZE_PIXELTYPE_NONE); 1601 buffer.writeInt(SERIALIZE_PIXELTYPE_NONE);
1601 } 1602 }
1602 } 1603 }
1603 1604
1604 void SkBitmap::unflatten(SkFlattenableReadBuffer& buffer) { 1605 void SkBitmap::unflatten(SkFlattenableReadBuffer& buffer) {
1605 this->reset(); 1606 this->reset();
1606 1607
1607 int width = buffer.readInt(); 1608 int width = buffer.readInt();
1608 int height = buffer.readInt(); 1609 int height = buffer.readInt();
1609 int rowBytes = buffer.readInt(); 1610 int rowBytes = buffer.readInt();
1610 int config = buffer.readInt(); 1611 Config config = (Config)buffer.readInt();
1612 buffer.validateData((width >= 0) && (height >= 0) && (rowBytes >= 0) &&
1613 IsValidConfig(config));
1611 1614
1612 this->setConfig((Config)config, width, height, rowBytes); 1615 this->setConfig(config, width, height, rowBytes);
1613 this->setIsOpaque(buffer.readBool()); 1616 this->setIsOpaque(buffer.readBool());
1614 1617
1615 int reftype = buffer.readInt(); 1618 int reftype = buffer.readInt();
1616 switch (reftype) { 1619 switch (reftype) {
1617 case SERIALIZE_PIXELTYPE_REF_DATA: { 1620 case SERIALIZE_PIXELTYPE_REF_DATA: {
1618 size_t offset = buffer.readUInt(); 1621 size_t offset = buffer.readUInt();
1619 SkPixelRef* pr = buffer.readFlattenableT<SkPixelRef>(); 1622 SkPixelRef* pr = buffer.readFlattenableT<SkPixelRef>();
1620 SkSafeUnref(this->setPixelRef(pr, offset)); 1623 SkSafeUnref(this->setPixelRef(pr, offset));
1621 break; 1624 break;
1622 } 1625 }
1623 case SERIALIZE_PIXELTYPE_NONE: 1626 case SERIALIZE_PIXELTYPE_NONE:
1624 break; 1627 break;
1625 default: 1628 default:
1629 buffer.validateData(false);
1626 SkDEBUGFAIL("unrecognized pixeltype in serialized data"); 1630 SkDEBUGFAIL("unrecognized pixeltype in serialized data");
1627 sk_throw(); 1631 sk_throw();
1628 } 1632 }
1629 } 1633 }
1630 1634
1631 /////////////////////////////////////////////////////////////////////////////// 1635 ///////////////////////////////////////////////////////////////////////////////
1632 1636
1633 SkBitmap::RLEPixels::RLEPixels(int width, int height) { 1637 SkBitmap::RLEPixels::RLEPixels(int width, int height) {
1634 fHeight = height; 1638 fHeight = height;
1635 fYPtrs = (uint8_t**)sk_malloc_throw(height * sizeof(uint8_t*)); 1639 fYPtrs = (uint8_t**)sk_malloc_throw(height * sizeof(uint8_t*));
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1700 if (NULL != uri) { 1704 if (NULL != uri) {
1701 str->appendf(" uri:\"%s\"", uri); 1705 str->appendf(" uri:\"%s\"", uri);
1702 } else { 1706 } else {
1703 str->appendf(" pixelref:%p", pr); 1707 str->appendf(" pixelref:%p", pr);
1704 } 1708 }
1705 } 1709 }
1706 1710
1707 str->append(")"); 1711 str->append(")");
1708 } 1712 }
1709 #endif 1713 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698