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

Unified Diff: cc/resources/texture_mailbox.cc

Issue 220093002: cc: Prevent integer overflow with software TextureMailbox. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 | « cc/resources/texture_mailbox.h ('k') | content/browser/renderer_host/render_widget_host_view_aura.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/resources/texture_mailbox.cc
diff --git a/cc/resources/texture_mailbox.cc b/cc/resources/texture_mailbox.cc
index a08930d07699a7d3259dec2d240001295a754efc..8c1a6ede9e1f8327f87a18cac022467db8ba06bc 100644
--- a/cc/resources/texture_mailbox.cc
+++ b/cc/resources/texture_mailbox.cc
@@ -27,7 +27,11 @@ TextureMailbox::TextureMailbox(base::SharedMemory* shared_memory,
const gfx::Size& size)
: shared_memory_(shared_memory),
shared_memory_size_(size),
- allow_overlay_(false) {}
+ allow_overlay_(false) {
+ // If an embedder of cc gives an invalid TextureMailbox, we should crash
+ // safely rather than overflow.
+ CHECK(CheckedSharedMemorySizeInBytes().IsValid());
piman 2014/03/31 22:33:54 Can cc generate one for mask layers (not tiled)?
danakj 2014/03/31 22:34:50 We don't make a TextureMailbox in that case. It's
+}
TextureMailbox::~TextureMailbox() {}
@@ -45,8 +49,18 @@ bool TextureMailbox::Equals(const TextureMailbox& other) const {
return !IsValid();
}
-size_t TextureMailbox::shared_memory_size_in_bytes() const {
- return 4 * shared_memory_size_.GetArea();
+size_t TextureMailbox::SharedMemorySizeInBytes() const {
+ size_t bytes_per_pixel = 4;
+ size_t width = shared_memory_size_.width();
+ size_t height = shared_memory_size_.height();
+ return bytes_per_pixel * width * height;
+}
+
+base::CheckedNumeric<size_t> TextureMailbox::CheckedSharedMemorySizeInBytes()
+ const {
+ return base::CheckedNumeric<size_t>(4) *
+ base::CheckedNumeric<size_t>(shared_memory_size_.width()) *
+ base::CheckedNumeric<size_t>(shared_memory_size_.height());
}
} // namespace cc
« no previous file with comments | « cc/resources/texture_mailbox.h ('k') | content/browser/renderer_host/render_widget_host_view_aura.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698