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

Unified Diff: cc/resources/resource_provider.cc

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
« cc/resources/resource.h ('K') | « cc/resources/resource.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/resources/resource_provider.cc
diff --git a/cc/resources/resource_provider.cc b/cc/resources/resource_provider.cc
index 07ce62c88352cfad3533970f4261ba455bd9d215..449e04be23750e28d015ef04a50014eee0977f00 100644
--- a/cc/resources/resource_provider.cc
+++ b/cc/resources/resource_provider.cc
@@ -9,6 +9,7 @@
#include "base/containers/hash_tables.h"
#include "base/metrics/histogram.h"
+#include "base/numerics/safe_math.h"
#include "base/stl_util.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
@@ -772,12 +773,13 @@ void ResourceProvider::CopyToResource(ResourceId id,
gl->BindTexture(GL_TEXTURE_2D, resource->gl_id);
if (resource->format == ETC1) {
- // TODO(vmpstr): Make this overflow safe. crbug.com/495867
- int num_bytes =
- image_size.width() * image_size.height() * BitsPerPixel(ETC1) / 8;
+ base::CheckedNumeric<int> num_bytes = BitsPerPixel(ETC1);
danakj 2015/06/04 19:02:38 This function is called with less trustworthy info
+ num_bytes *= image_size.width();
+ num_bytes *= image_size.height();
+ num_bytes /= 8;
gl->CompressedTexImage2D(GL_TEXTURE_2D, 0, GLInternalFormat(ETC1),
image_size.width(), image_size.height(), 0,
- num_bytes, image);
+ num_bytes.ValueOrDie(), image);
} else {
gl->TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, image_size.width(),
image_size.height(), GLDataFormat(resource->format),
« cc/resources/resource.h ('K') | « cc/resources/resource.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698