ui/gfx: Make gfx::Size::GetArea use checked math.

This patch ensures that if the area calculation would overflow, we
instead fail a CHECK.

R=danakj, pkasting@chromium.org
BUG=352761

Review URL: https://codereview.chromium.org/1371753004

Cr-Commit-Position: refs/heads/master@{#353594}


CrOS-Libchrome-Original-Commit: 35f226abcae1a7143e9574b31e391a8e8e0c26ae
diff --git a/ui/gfx/geometry/size.cc b/ui/gfx/geometry/size.cc
index 86e1aeb..e58bb22 100644
--- a/ui/gfx/geometry/size.cc
+++ b/ui/gfx/geometry/size.cc
@@ -12,6 +12,7 @@
 #include <ApplicationServices/ApplicationServices.h>
 #endif
 
+#include "base/numerics/safe_math.h"
 #include "base/strings/stringprintf.h"
 #include "ui/gfx/geometry/size_conversions.h"
 
@@ -44,7 +45,9 @@
 #endif
 
 int Size::GetArea() const {
-  return width() * height();
+  base::CheckedNumeric<int> checked_area = width();
+  checked_area *= height();
+  return checked_area.ValueOrDie();
 }
 
 void Size::Enlarge(int grow_width, int grow_height) {
diff --git a/ui/gfx/geometry/size.h b/ui/gfx/geometry/size.h
index 7549786..27face1 100644
--- a/ui/gfx/geometry/size.h
+++ b/ui/gfx/geometry/size.h
@@ -47,6 +47,7 @@
   void set_width(int width) { width_ = width < 0 ? 0 : width; }
   void set_height(int height) { height_ = height < 0 ? 0 : height; }
 
+  // This call will CHECK if the area of this size would overflow int.
   int GetArea() const;
 
   void SetSize(int width, int height) {