Add cursor size validation to Wayland capture

Limit maximum cursor size we accept to 1024x1024 to reject unreasonably
large cursor metadata from PipeWire.

Also promote existing constants from const to constexpr.

Bug: chromium:507743672
Change-Id: Ie6499ea49a76f7c3520b03c2dc1e6f9b3ba74fab
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/468340
Reviewed-by: Andreas Pehrson <apehrson@mozilla.com>
Reviewed-by: Alexander Cooper <alcooper@chromium.org>
Commit-Queue: Jan Grulich <grulja@gmail.com>
Cr-Commit-Position: refs/heads/main@{#47588}
diff --git a/modules/desktop_capture/linux/wayland/shared_screencast_stream.cc b/modules/desktop_capture/linux/wayland/shared_screencast_stream.cc
index 1aa8be5..0bced6d 100644
--- a/modules/desktop_capture/linux/wayland/shared_screencast_stream.cc
+++ b/modules/desktop_capture/linux/wayland/shared_screencast_stream.cc
@@ -62,13 +62,13 @@
 
 namespace webrtc {
 
-const int kBytesPerPixel = 4;
-const int kVideoDamageRegionCount = 16;
+constexpr int kBytesPerPixel = 4;
+constexpr int kMaxCursorSize = 1024;
+constexpr int kVideoDamageRegionCount = 16;
 
-constexpr int kCursorBpp = 4;
 constexpr int CursorMetaSize(int w, int h) {
   return (sizeof(struct spa_meta_cursor) + sizeof(struct spa_meta_bitmap) +
-          w * h * kCursorBpp);
+          w * h * kBytesPerPixel);
 }
 
 constexpr PipeWireVersion kDmaBufModifierMinVersion = {.major = 0,
@@ -766,7 +766,9 @@
           bitmap =
               SPA_MEMBER(cursor, cursor->bitmap_offset, struct spa_meta_bitmap);
 
-        if (bitmap && bitmap->size.width > 0 && bitmap->size.height > 0) {
+        if (bitmap && bitmap->size.width > 0 &&
+            bitmap->size.width <= kMaxCursorSize && bitmap->size.height > 0 &&
+            bitmap->size.height <= kMaxCursorSize) {
           const uint8_t* bitmap_data =
               SPA_MEMBER(bitmap, bitmap->offset, uint8_t);
           // TODO(bugs.webrtc.org/436974448): Convert `spa_video_format` to