Don't send cursor shape messages if they are too large.

Bug: 1008668
Change-Id: I600b369cb5a4a8cfa8cb0cf3dac025457cabbd52
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1828357
Reviewed-by: Erik Jensen <[email protected]>
Commit-Queue: Jamie Walch <[email protected]>
Cr-Commit-Position: refs/heads/master@{#700559}
diff --git a/remoting/protocol/host_control_dispatcher.cc b/remoting/protocol/host_control_dispatcher.cc
index 9aa060f..b383308d 100644
--- a/remoting/protocol/host_control_dispatcher.cc
+++ b/remoting/protocol/host_control_dispatcher.cc
@@ -67,6 +67,14 @@
     const CursorShapeInfo& cursor_shape) {
   ControlMessage message;
   message.mutable_cursor_shape()->CopyFrom(cursor_shape);
+  std::size_t message_size = message.ByteSizeLong();
+  if (message_size > max_message_size_) {
+    // Better to drop the event than drop the connection, which can happen if
+    // the browser receives a message larger than it can handle.
+    LOG(WARNING) << "Cursor message dropped because message size "
+                 << message_size << " is larger than " << max_message_size_;
+    return;
+  }
   message_pipe()->Send(&message, base::Closure());
 }