diff --git a/ui/gfx/geometry/size.cc b/ui/gfx/geometry/size.cc index 86e1aeb9b174f9..e58bb22fd8e535 100644 --- a/ui/gfx/geometry/size.cc +++ b/ui/gfx/geometry/size.cc @@ -12,6 +12,7 @@ #include #endif +#include "base/numerics/safe_math.h" #include "base/strings/stringprintf.h" #include "ui/gfx/geometry/size_conversions.h" @@ -44,7 +45,9 @@ CGSize Size::ToCGSize() const { #endif int Size::GetArea() const { - return width() * height(); + base::CheckedNumeric 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 754978672e9054..27face1d9c7ce4 100644 --- a/ui/gfx/geometry/size.h +++ b/ui/gfx/geometry/size.h @@ -47,6 +47,7 @@ class GFX_EXPORT Size { 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) {