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

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

Issue 1319973008: fix bounds check for ctables (thanks Hal) (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2009 The Android Open Source Project 3 * Copyright 2009 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 "SkColorTable.h" 10 #include "SkColorTable.h"
(...skipping 18 matching lines...) Expand all
29 } else if (count > 256) { 29 } else if (count > 256) {
30 count = 256; 30 count = 256;
31 } 31 }
32 this->init(colors, count); 32 this->init(colors, count);
33 } 33 }
34 34
35 SkColorTable::SkColorTable(SkPMColor* colors, int count, AllocatedWithMalloc) 35 SkColorTable::SkColorTable(SkPMColor* colors, int count, AllocatedWithMalloc)
36 : fColors(colors) 36 : fColors(colors)
37 , fCount(count) 37 , fCount(count)
38 { 38 {
39 SkASSERT(count > 0 && count <= 255); 39 SkASSERT(count > 0 && count <= 256);
40 SkASSERT(colors); 40 SkASSERT(colors);
41 } 41 }
42 42
43 SkColorTable::~SkColorTable() { 43 SkColorTable::~SkColorTable() {
44 sk_free(fColors); 44 sk_free(fColors);
45 // f16BitCache frees itself 45 // f16BitCache frees itself
46 } 46 }
47 47
48 #include "SkColorPriv.h" 48 #include "SkColorPriv.h"
49 49
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 SkColorTable* SkColorTable::Create(SkReadBuffer& buffer) { 101 SkColorTable* SkColorTable::Create(SkReadBuffer& buffer) {
102 if (buffer.isVersionLT(SkReadBuffer::kRemoveColorTableAlpha_Version)) { 102 if (buffer.isVersionLT(SkReadBuffer::kRemoveColorTableAlpha_Version)) {
103 /*fAlphaType = */buffer.readUInt(); 103 /*fAlphaType = */buffer.readUInt();
104 } 104 }
105 105
106 const int count = buffer.getArrayCount(); 106 const int count = buffer.getArrayCount();
107 if (0 == count) { 107 if (0 == count) {
108 return new SkColorTable(nullptr, 0); 108 return new SkColorTable(nullptr, 0);
109 } 109 }
110 110
111 if (count < 0 || count > 255) { 111 if (count < 0 || count > 256) {
112 buffer.validate(false); 112 buffer.validate(false);
113 return nullptr; 113 return nullptr;
114 } 114 }
115 115
116 const size_t allocSize = count * sizeof(SkPMColor); 116 const size_t allocSize = count * sizeof(SkPMColor);
117 SkAutoTDelete<SkPMColor> colors((SkPMColor*)sk_malloc_throw(allocSize)); 117 SkAutoTDelete<SkPMColor> colors((SkPMColor*)sk_malloc_throw(allocSize));
118 if (!buffer.readColorArray(colors, count)) { 118 if (!buffer.readColorArray(colors, count)) {
119 return nullptr; 119 return nullptr;
120 } 120 }
121 121
122 return new SkColorTable(colors.detach(), count, kAllocatedWithMalloc); 122 return new SkColorTable(colors.detach(), count, kAllocatedWithMalloc);
123 } 123 }
124 124
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698