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

Unified Diff: content/common/cc_messages_unittest.cc

Issue 196423027: Move SoftwareFrameData overflow checks to the IPC code. (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
« content/common/cc_messages.cc ('K') | « content/common/cc_messages.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/common/cc_messages_unittest.cc
diff --git a/content/common/cc_messages_unittest.cc b/content/common/cc_messages_unittest.cc
index 7711c23f38c8575feb161326bf6c1ad414f30eaa..67d9cf9552e11e1d8910cb8ce7b41326ecfbccb7 100644
--- a/content/common/cc_messages_unittest.cc
+++ b/content/common/cc_messages_unittest.cc
@@ -14,6 +14,10 @@
#include "third_party/khronos/GLES2/gl2ext.h"
#include "third_party/skia/include/effects/SkBlurImageFilter.h"
+#if defined(OS_POSIX)
+#include "base/file_descriptor_posix.h"
+#endif
+
using cc::CheckerboardDrawQuad;
using cc::DelegatedFrameData;
using cc::DebugBorderDrawQuad;
@@ -26,6 +30,7 @@ using cc::RenderPass;
using cc::RenderPassDrawQuad;
using cc::ResourceProvider;
using cc::SharedQuadState;
+using cc::SoftwareFrameData;
using cc::SolidColorDrawQuad;
using cc::SurfaceDrawQuad;
using cc::TextureDrawQuad;
@@ -742,5 +747,59 @@ TEST_F(CCMessagesTest, LargestQuadType) {
EXPECT_EQ(sizeof(RenderPassDrawQuad), largest);
}
+TEST_F(CCMessagesTest, SoftwareFrameData) {
+ cc::SoftwareFrameData frame_in;
+ frame_in.id = 3;
+ frame_in.size = gfx::Size(40, 20);
+ frame_in.damage_rect = gfx::Rect(5, 18, 31, 44);
+#if defined(OS_WIN)
+ frame_in.handle = reinterpret_cast<base::SharedMemoryHandle>(23);
+#elif defined(OS_POSIX)
+ frame_in.handle = base::FileDescriptor(23, true);
+#endif
+
+ // Write the frame.
+ IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
+ IPC::ParamTraits<cc::SoftwareFrameData>::Write(&msg, frame_in);
+
+ // Read the frame.
+ cc::SoftwareFrameData frame_out;
+ PickleIterator iter(msg);
+ EXPECT_TRUE(
+ IPC::ParamTraits<SoftwareFrameData>::Read(&msg, &iter, &frame_out));
+ EXPECT_EQ(frame_in.id, frame_out.id);
+ EXPECT_EQ(frame_in.size.ToString(), frame_out.size.ToString());
+ EXPECT_EQ(frame_in.damage_rect.ToString(), frame_out.damage_rect.ToString());
+ EXPECT_EQ(frame_in.handle, frame_out.handle);
+}
+
+TEST_F(CCMessagesTest, SoftwareFrameDataMaxInt) {
+ int max = std::numeric_limits<int>::max();
+
+ // The size of the frame will overflow when multiplied together.
+ SoftwareFrameData frame_in;
+ frame_in.id = 3;
+ frame_in.size = gfx::Size(max, max);
+ frame_in.damage_rect = gfx::Rect(5, 18, 31, 44);
+#if defined(OS_WIN)
+ frame_in.handle = reinterpret_cast<base::SharedMemoryHandle>(23);
+#elif defined(OS_POSIX)
+ frame_in.handle = base::FileDescriptor(23, true);
+#endif
+
+ // Write the frame.
+ IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
+ IPC::ParamTraits<SoftwareFrameData>::Write(&msg, frame_in);
+
+ // If size_t is larger than int, then int*int*4 can always fit in size_t.
+ bool expect_read = sizeof(size_t) >= sizeof(int) * 2;
+
+ // Read the frame.
+ SoftwareFrameData frame_out;
+ PickleIterator iter(msg);
+ EXPECT_EQ(expect_read,
+ IPC::ParamTraits<SoftwareFrameData>::Read(&msg, &iter, &frame_out));
+}
+
} // namespace
} // namespace content
« content/common/cc_messages.cc ('K') | « content/common/cc_messages.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698