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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkData.cpp
diff --git a/src/core/SkData.cpp b/src/core/SkData.cpp
index dfbd00384975d93a622c7eabeccfaf5d8b091bd0..ad79ce05350064b128a4e210f7b4ef135ee896af 100644
--- a/src/core/SkData.cpp
+++ b/src/core/SkData.cpp
@@ -63,7 +63,14 @@ SkData* SkData::PrivateNewWithCopy(const void* srcOrNull, size_t length) {
if (0 == length) {
return SkData::NewEmpty();
}
- char* storage = (char*)sk_malloc_throw(sizeof(SkData) + length);
+
+ const size_t actualLength = length + sizeof(SkData);
+ if (actualLength < length) {
+ // we overflowed
+ sk_throw();
+ }
+
+ char* storage = (char*)sk_malloc_throw(actualLength);
SkData* data = new (storage) SkData(length);
if (srcOrNull) {
memcpy(data->writable_data(), srcOrNull, length);
« 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