summaryrefslogtreecommitdiffstats
path: root/cc/resources/shared_bitmap.cc
diff options
context:
space:
mode:
authorscottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-05 17:58:16 +0000
committerscottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-05 17:58:16 +0000
commit265872e2075fee88ddc351acd7551d2fca2f305a (patch)
treeeb65790ba81efcf60150ec8ef42511ca26fc81c8 /cc/resources/shared_bitmap.cc
parent030a0491b1d2e0bda3933e0d1f4a6a90c0b06853 (diff)
downloadchromium_src-265872e2075fee88ddc351acd7551d2fca2f305a.zip
chromium_src-265872e2075fee88ddc351acd7551d2fca2f305a.tar.gz
chromium_src-265872e2075fee88ddc351acd7551d2fca2f305a.tar.bz2
Revert 261972 "Revert 261817 "cc: Remove all usage of GetArea() ..."
r261817 falsely accused! Reverting the revert, sorry for the noise. > Revert 261817 "cc: Remove all usage of GetArea() from production..." > > Suspected of causing failures on Linux CrOS ASan LSan: > > http://build.chromium.org/p/chromium.memory/builders/Linux%20Chromium%20OS%20ASan%2BLSan%20Tests%20%283%29/builds/702 > > http://build.chromium.org/p/chromium.memory/builders/Linux%20Chromium%20OS%20ASan%2BLSan%20Tests%20%282%29/builds/664 > > http://build.chromium.org/p/chromium.memory/builders/Linux%20Chromium%20OS%20ASan%2BLSan%20Tests%20%281%29/builds/702 > > > > cc: Remove all usage of GetArea() from production code in cc > > > > Consolidate the calls to turn gfx::Size into a number of bytes onto > > the cc::SharedBitmap class. The class offers the following methods: > > 1. Get a size_t bytes and bool saying if you overflowed or not. > > 2. Get a size_t bytes and crash if you overflow. > > 3. Get a size_t bytes and don't check for overflow. > > 4. Tell me if the gfx::Size would overflow to create the size_t bytes. > > > > These were the use cases I found in the existing code, plus the > > addition of case 2. A few places that were finding the size_t bytes > > without looking for overflow (case 3), from a previously-unchecked > > gfx::Size, were changed to crash on overflow instead (case 2). > > > > R=jbauman@chromium.org, piman@chromium.org > > BUG=348332 > > > > Review URL: https://codereview.chromium.org/221523003 > > TBR=danakj@chromium.org > > Review URL: https://codereview.chromium.org/226693005 TBR=scottmg@chromium.org, danakj@chromium.org Review URL: https://codereview.chromium.org/226693007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@262022 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/resources/shared_bitmap.cc')
-rw-r--r--cc/resources/shared_bitmap.cc40
1 files changed, 34 insertions, 6 deletions
diff --git a/cc/resources/shared_bitmap.cc b/cc/resources/shared_bitmap.cc
index 3b94d45..6d2ff0a 100644
--- a/cc/resources/shared_bitmap.cc
+++ b/cc/resources/shared_bitmap.cc
@@ -4,6 +4,7 @@
#include "cc/resources/shared_bitmap.h"
+#include "base/logging.h"
#include "base/numerics/safe_math.h"
#include "base/rand_util.h"
@@ -12,19 +13,18 @@ namespace cc {
SharedBitmap::SharedBitmap(
base::SharedMemory* memory,
const SharedBitmapId& id,
- const base::Callback<void(SharedBitmap*)>& free_callback)
+ const base::Callback<void(SharedBitmap* bitmap)>& free_callback)
: memory_(memory), id_(id), free_callback_(free_callback) {}
SharedBitmap::~SharedBitmap() { free_callback_.Run(this); }
// static
-bool SharedBitmap::GetSizeInBytes(const gfx::Size& size,
- size_t* size_in_bytes) {
- if (size.width() <= 0 || size.height() <= 0)
+bool SharedBitmap::SizeInBytes(const gfx::Size& size, size_t* size_in_bytes) {
+ if (size.IsEmpty())
return false;
- base::CheckedNumeric<int> s = size.width();
+ base::CheckedNumeric<size_t> s = 4;
+ s *= size.width();
s *= size.height();
- s *= 4;
if (!s.IsValid())
return false;
*size_in_bytes = s.ValueOrDie();
@@ -32,6 +32,34 @@ bool SharedBitmap::GetSizeInBytes(const gfx::Size& size,
}
// static
+size_t SharedBitmap::CheckedSizeInBytes(const gfx::Size& size) {
+ CHECK(!size.IsEmpty());
+ base::CheckedNumeric<size_t> s = 4;
+ s *= size.width();
+ s *= size.height();
+ return s.ValueOrDie();
+}
+
+// static
+size_t SharedBitmap::UncheckedSizeInBytes(const gfx::Size& size) {
+ DCHECK(VerifySizeInBytes(size));
+ size_t s = 4;
+ s *= size.width();
+ s *= size.height();
+ return s;
+}
+
+// static
+bool SharedBitmap::VerifySizeInBytes(const gfx::Size& size) {
+ if (size.IsEmpty())
+ return false;
+ base::CheckedNumeric<size_t> s = 4;
+ s *= size.width();
+ s *= size.height();
+ return s.IsValid();
+}
+
+// static
SharedBitmapId SharedBitmap::GenerateId() {
SharedBitmapId id;
// Needs cryptographically-secure random numbers.