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

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

Issue 1148873004: check for big sizes in NewData (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 * 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 7
8 #include "SkData.h" 8 #include "SkData.h"
9 #include "SkLazyPtr.h" 9 #include "SkLazyPtr.h"
10 #include "SkOSFile.h" 10 #include "SkOSFile.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 SkASSERT(length > 0); 56 SkASSERT(length > 0);
57 57
58 memcpy(buffer, this->bytes() + offset, length); 58 memcpy(buffer, this->bytes() + offset, length);
59 return length; 59 return length;
60 } 60 }
61 61
62 SkData* SkData::PrivateNewWithCopy(const void* srcOrNull, size_t length) { 62 SkData* SkData::PrivateNewWithCopy(const void* srcOrNull, size_t length) {
63 if (0 == length) { 63 if (0 == length) {
64 return SkData::NewEmpty(); 64 return SkData::NewEmpty();
65 } 65 }
66 char* storage = (char*)sk_malloc_throw(sizeof(SkData) + length); 66
67 const size_t actualLength = length + sizeof(SkData);
68 if (actualLength < length) {
69 // we overflowed
70 sk_throw();
71 }
72
73 char* storage = (char*)sk_malloc_throw(actualLength);
67 SkData* data = new (storage) SkData(length); 74 SkData* data = new (storage) SkData(length);
68 if (srcOrNull) { 75 if (srcOrNull) {
69 memcpy(data->writable_data(), srcOrNull, length); 76 memcpy(data->writable_data(), srcOrNull, length);
70 } 77 }
71 return data; 78 return data;
72 } 79 }
73 80
74 /////////////////////////////////////////////////////////////////////////////// 81 ///////////////////////////////////////////////////////////////////////////////
75 82
76 // As a template argument these must have external linkage. 83 // As a template argument these must have external linkage.
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 /////////////////////////////////////////////////////////////////////////////// 190 ///////////////////////////////////////////////////////////////////////////////
184 191
185 SkData* SkData::NewFromStream(SkStream* stream, size_t size) { 192 SkData* SkData::NewFromStream(SkStream* stream, size_t size) {
186 SkAutoDataUnref data(SkData::NewUninitialized(size)); 193 SkAutoDataUnref data(SkData::NewUninitialized(size));
187 if (stream->read(data->writable_data(), size) != size) { 194 if (stream->read(data->writable_data(), size) != size) {
188 return NULL; 195 return NULL;
189 } 196 }
190 return data.detach(); 197 return data.detach();
191 } 198 }
192 199
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