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

Unified Diff: include/core/SkTemplates.h

Issue 831583004: Adding check on input count (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Added overflow detection in SkAutoSTArray::reset Created 5 years, 11 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: include/core/SkTemplates.h
diff --git a/include/core/SkTemplates.h b/include/core/SkTemplates.h
index 3571af6706a7b13b7e07de2489fd999ebd1c4c91..6ab44394d898c58cab23f270ae3edf4a0ee64905 100644
--- a/include/core/SkTemplates.h
+++ b/include/core/SkTemplates.h
@@ -10,6 +10,7 @@
#ifndef SkTemplates_DEFINED
#define SkTemplates_DEFINED
+#include "SkMath.h"
#include "SkTypes.h"
#include <limits.h>
#include <new>
@@ -292,7 +293,12 @@ public:
}
if (count > N) {
- fArray = (T*) sk_malloc_throw(count * sizeof(T));
+ const uint64_t size64 = sk_64_mul(count, sizeof(T));
+ const size_t size = static_cast<size_t>(size64);
+ if (size != size64) {
+ sk_out_of_memory();
+ }
+ fArray = (T*) sk_malloc_throw(size);
} else if (count > 0) {
fArray = (T*) fStorage;
} else {
« 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