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

Unified Diff: cc/resources/resource.h

Issue 1154393003: cc: Use CheckedNumeric for resource size calculations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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 | cc/resources/resource_provider.cc » ('j') | cc/resources/resource_provider.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/resources/resource.h
diff --git a/cc/resources/resource.h b/cc/resources/resource.h
index 0e3c3df688387b9ee927f150737bc8dd37a7a6b7..06893fe32749dad1a8d960302dcd80347b065316 100644
--- a/cc/resources/resource.h
+++ b/cc/resources/resource.h
@@ -5,6 +5,7 @@
#ifndef CC_RESOURCES_RESOURCE_H_
#define CC_RESOURCES_RESOURCE_H_
+#include "base/numerics/safe_math.h"
#include "cc/base/cc_export.h"
#include "cc/resources/resource_provider.h"
#include "ui/gfx/geometry/size.h"
@@ -27,9 +28,11 @@ class CC_EXPORT Resource {
inline static size_t MemorySizeBytes(const gfx::Size& size,
ResourceFormat format) {
DCHECK_EQ(0, (BitsPerPixel(format) * size.width() * size.height()) % 8);
- // TODO(vmpstr): Make this function overflow safe. crbug.com/495867
- return static_cast<size_t>(
- (BitsPerPixel(format) * size.width() * size.height()) / 8);
+ base::CheckedNumeric<size_t> result = BitsPerPixel(format);
+ result *= size.width();
+ result *= size.height();
+ result /= 8;
+ return result.ValueOrDie();
danakj 2015/06/04 19:02:38 This would work, but looking at the callsites of M
}
protected:
« no previous file with comments | « no previous file | cc/resources/resource_provider.cc » ('j') | cc/resources/resource_provider.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698