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

Side by Side Diff: src/core/SkRegionPriv.h

Issue 1143603003: Prevent integer wrap around for malloc size when creating a SkRegion (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: simplify Created 5 years, 7 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 2006 The Android Open Source Project 3 * Copyright 2006 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 #ifndef SkRegionPriv_DEFINED 10 #ifndef SkRegionPriv_DEFINED
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 int getIntervalCount() const { 58 int getIntervalCount() const {
59 return fIntervalCount; 59 return fIntervalCount;
60 } 60 }
61 61
62 static RunHead* Alloc(int count) { 62 static RunHead* Alloc(int count) {
63 //SkDEBUGCODE(sk_atomic_inc(&gRgnAllocCounter);) 63 //SkDEBUGCODE(sk_atomic_inc(&gRgnAllocCounter);)
64 //SkDEBUGF(("************** gRgnAllocCounter::alloc %d\n", gRgnAllocCoun ter)); 64 //SkDEBUGF(("************** gRgnAllocCounter::alloc %d\n", gRgnAllocCoun ter));
65 65
66 SkASSERT(count >= SkRegion::kRectRegionRuns); 66 SkASSERT(count >= SkRegion::kRectRegionRuns);
67 67
68 RunHead* head = (RunHead*)sk_malloc_throw(sizeof(RunHead) + count * size of(RunType)); 68 const int64_t size = sk_64_mul(count, sizeof(RunType)) + sizeof(RunHead) ;
69 if (count < 0 || !sk_64_isS32(size)) { SK_CRASH(); }
70
71 RunHead* head = (RunHead*)sk_malloc_throw(size);
69 head->fRefCnt = 1; 72 head->fRefCnt = 1;
70 head->fRunCount = count; 73 head->fRunCount = count;
71 // these must be filled in later, otherwise we will be invalid 74 // these must be filled in later, otherwise we will be invalid
72 head->fYSpanCount = 0; 75 head->fYSpanCount = 0;
73 head->fIntervalCount = 0; 76 head->fIntervalCount = 0;
74 return head; 77 return head;
75 } 78 }
76 79
77 static RunHead* Alloc(int count, int yspancount, int intervalCount) { 80 static RunHead* Alloc(int count, int yspancount, int intervalCount) {
78 SkASSERT(yspancount > 0); 81 SkASSERT(yspancount > 0);
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 bounds->fRight = rite; 227 bounds->fRight = rite;
225 bounds->fBottom = bot; 228 bounds->fBottom = bot;
226 } 229 }
227 230
228 private: 231 private:
229 int32_t fYSpanCount; 232 int32_t fYSpanCount;
230 int32_t fIntervalCount; 233 int32_t fIntervalCount;
231 }; 234 };
232 235
233 #endif 236 #endif
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