From 4574b97752af4631a24121b4620786033a4f8651 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Fri, 17 Feb 2023 14:17:37 +0100 Subject: [PATCH] Fix crash with bogus shape index to DisplayServer.cursor_set_custom_image() Fixes #66605. --- platform/android/display_server_android.cpp | 2 ++ platform/linuxbsd/x11/display_server_x11.cpp | 2 ++ platform/macos/display_server_macos.mm | 2 ++ platform/web/display_server_web.cpp | 1 + platform/windows/display_server_windows.cpp | 2 ++ 5 files changed, 9 insertions(+) diff --git a/platform/android/display_server_android.cpp b/platform/android/display_server_android.cpp index 3fcb926f864..af4ba1255b7 100644 --- a/platform/android/display_server_android.cpp +++ b/platform/android/display_server_android.cpp @@ -656,6 +656,7 @@ void DisplayServerAndroid::_cursor_set_shape_helper(CursorShape p_shape, bool fo } void DisplayServerAndroid::cursor_set_shape(DisplayServer::CursorShape p_shape) { + ERR_FAIL_INDEX(p_shape, CURSOR_MAX); _cursor_set_shape_helper(p_shape); } @@ -664,6 +665,7 @@ DisplayServer::CursorShape DisplayServerAndroid::cursor_get_shape() const { } void DisplayServerAndroid::cursor_set_custom_image(const Ref &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) { + ERR_FAIL_INDEX(p_shape, CURSOR_MAX); String cursor_path = p_cursor.is_valid() ? p_cursor->get_path() : ""; if (!cursor_path.is_empty()) { cursor_path = ProjectSettings::get_singleton()->globalize_path(cursor_path); diff --git a/platform/linuxbsd/x11/display_server_x11.cpp b/platform/linuxbsd/x11/display_server_x11.cpp index 896b7b95eb9..00547c45604 100644 --- a/platform/linuxbsd/x11/display_server_x11.cpp +++ b/platform/linuxbsd/x11/display_server_x11.cpp @@ -2599,6 +2599,8 @@ DisplayServerX11::CursorShape DisplayServerX11::cursor_get_shape() const { void DisplayServerX11::cursor_set_custom_image(const Ref &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) { _THREAD_SAFE_METHOD_ + ERR_FAIL_INDEX(p_shape, CURSOR_MAX); + if (p_cursor.is_valid()) { HashMap>::Iterator cursor_c = cursors_cache.find(p_shape); diff --git a/platform/macos/display_server_macos.mm b/platform/macos/display_server_macos.mm index 65546392c19..14778b5f037 100644 --- a/platform/macos/display_server_macos.mm +++ b/platform/macos/display_server_macos.mm @@ -3284,6 +3284,8 @@ DisplayServerMacOS::CursorShape DisplayServerMacOS::cursor_get_shape() const { void DisplayServerMacOS::cursor_set_custom_image(const Ref &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) { _THREAD_SAFE_METHOD_ + ERR_FAIL_INDEX(p_shape, CURSOR_MAX); + if (p_cursor.is_valid()) { HashMap>::Iterator cursor_c = cursors_cache.find(p_shape); diff --git a/platform/web/display_server_web.cpp b/platform/web/display_server_web.cpp index e89a79834b6..565d439a92c 100644 --- a/platform/web/display_server_web.cpp +++ b/platform/web/display_server_web.cpp @@ -395,6 +395,7 @@ DisplayServer::CursorShape DisplayServerWeb::cursor_get_shape() const { } void DisplayServerWeb::cursor_set_custom_image(const Ref &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) { + ERR_FAIL_INDEX(p_shape, CURSOR_MAX); if (p_cursor.is_valid()) { Ref texture = p_cursor; Ref atlas_texture = p_cursor; diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp index 1cfc9c9f474..d2889a3442b 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -1719,6 +1719,8 @@ DisplayServer::CursorShape DisplayServerWindows::cursor_get_shape() const { void DisplayServerWindows::cursor_set_custom_image(const Ref &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) { _THREAD_SAFE_METHOD_ + ERR_FAIL_INDEX(p_shape, CURSOR_MAX); + if (p_cursor.is_valid()) { RBMap>::Element *cursor_c = cursors_cache.find(p_shape);