|
| 1 | +From c313849c2e5133802e21b13fa0b141b360171d39 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Christian Persch <chpe@src.gnome.org> |
| 3 | +Date: Sun, 2 Jun 2024 19:19:35 +0200 |
| 4 | +Subject: [PATCH] widget: Add safety limit to widget size requests |
| 5 | + |
| 6 | +https://gitlab.gnome.org/GNOME/vte/-/issues/2786 |
| 7 | +(cherry picked from commit 1803ba866053a3d7840892b9d31fe2944a183eda) |
| 8 | +--- |
| 9 | + src/vtegtk.cc | 35 +++++++++++++++++++++++++++++++++++ |
| 10 | + 1 file changed, 35 insertions(+) |
| 11 | + |
| 12 | +diff --git a/src/vtegtk.cc b/src/vtegtk.cc |
| 13 | +index 24bdd7184..48cae79c1 100644 |
| 14 | +--- a/src/vtegtk.cc |
| 15 | ++++ b/src/vtegtk.cc |
| 16 | +@@ -91,6 +91,38 @@ |
| 17 | + template<typename T> |
| 18 | + constexpr bool check_enum_value(T value) noexcept; |
| 19 | + |
| 20 | ++static inline void |
| 21 | ++sanitise_widget_size_request(int* minimum, |
| 22 | ++ int* natural) noexcept |
| 23 | ++{ |
| 24 | ++ // Overly large size requests will make gtk happily allocate |
| 25 | ++ // a window size over the window system's limits (see |
| 26 | ++ // e.g. https://gitlab.gnome.org/GNOME/vte/-/issues/2786), |
| 27 | ++ // leading to aborting the whole process. |
| 28 | ++ // The toolkit should be in a better position to know about |
| 29 | ++ // these limits and not exceed them (which here is certainly |
| 30 | ++ // possible since our minimum sizes are very small), let's |
| 31 | ++ // limit the widget's size request to some large value |
| 32 | ++ // that hopefully is within the absolute limits of |
| 33 | ++ // the window system (assumed here to be int16 range, |
| 34 | ++ // and leaving some space for the widgets that contain |
| 35 | ++ // the terminal). |
| 36 | ++ auto const limit = (1 << 15) - (1 << 12); |
| 37 | ++ |
| 38 | ++ if (*minimum > limit || *natural > limit) { |
| 39 | ++ static auto warned = false; |
| 40 | ++ |
| 41 | ++ if (!warned) { |
| 42 | ++ g_warning("Widget size request (minimum %d, natural %d) exceeds limits\n", |
| 43 | ++ *minimum, *natural); |
| 44 | ++ warned = true; |
| 45 | ++ } |
| 46 | ++ } |
| 47 | ++ |
| 48 | ++ *minimum = std::min(*minimum, limit); |
| 49 | ++ *natural = std::clamp(*natural, *minimum, limit); |
| 50 | ++} |
| 51 | ++ |
| 52 | + struct _VteTerminalClassPrivate { |
| 53 | + GtkStyleProvider *style_provider; |
| 54 | + }; |
| 55 | +@@ -510,6 +542,7 @@ try |
| 56 | + { |
| 57 | + VteTerminal *terminal = VTE_TERMINAL(widget); |
| 58 | + WIDGET(terminal)->get_preferred_width(minimum_width, natural_width); |
| 59 | ++ sanitise_widget_size_request(minimum_width, natural_width); |
| 60 | + } |
| 61 | + catch (...) |
| 62 | + { |
| 63 | +@@ -524,6 +557,7 @@ try |
| 64 | + { |
| 65 | + VteTerminal *terminal = VTE_TERMINAL(widget); |
| 66 | + WIDGET(terminal)->get_preferred_height(minimum_height, natural_height); |
| 67 | ++ sanitise_widget_size_request(minimum_height, natural_height); |
| 68 | + } |
| 69 | + catch (...) |
| 70 | + { |
| 71 | +@@ -781,6 +815,7 @@ try |
| 72 | + WIDGET(terminal)->measure(orientation, for_size, |
| 73 | + minimum, natural, |
| 74 | + minimum_baseline, natural_baseline); |
| 75 | ++ sanitise_widget_size_request(minimum, natural); |
| 76 | + } |
| 77 | + catch (...) |
| 78 | + { |
| 79 | +-- |
0 commit comments