Fix crash when resizing the display

This crash happened when:
   * The cursor was located in the corner
   * The screen was resized so that the cursor position is outside of the frame.

This caused us to add out-of-bound coordinates to the frame's updated_region, which caused crashes further down the pipeline.

Bug: chromium:1323241
Test: new unittest
Test: manually reproduced crash
Change-Id: Ie71db58c8a347f00af8a3803fcd55cdcad6eafac
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/261263
Reviewed-by: Alexander Cooper <alcooper@chromium.org>
Commit-Queue: Jeroen Dhollander <jeroendh@google.com>
Cr-Commit-Position: refs/heads/main@{#36809}
This commit is contained in:
Jeroen Dhollander
2022-05-06 14:47:13 +02:00
committed by WebRTC LUCI CQ
parent 42a829e623
commit 77d987a724
2 changed files with 60 additions and 7 deletions

View File

@ -105,7 +105,11 @@ DesktopFrameWithCursor::DesktopFrameWithCursor(
if (!previous_cursor_rect.equals(cursor_rect_)) {
mutable_updated_region()->AddRect(cursor_rect_);
mutable_updated_region()->AddRect(previous_cursor_rect);
// Only add the previous cursor if it is inside the frame.
// (it can be outside the frame if the desktop has been resized).
if (original_frame_->rect().ContainsRect(previous_cursor_rect))
mutable_updated_region()->AddRect(previous_cursor_rect);
} else if (cursor_changed) {
mutable_updated_region()->AddRect(cursor_rect_);
}