File vte-widget-size-limits.patch of Package vte.34434
From 1803ba866053a3d7840892b9d31fe2944a183eda Mon Sep 17 00:00:00 2001
From: Christian Persch <chpe@src.gnome.org>
Date: Sun, 2 Jun 2024 19:13:15 +0200
Subject: [PATCH] widget: Add safety limit to widget size requests
https://gitlab.gnome.org/GNOME/vte/-/issues/2786
---
src/vtegtk.cc | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff -urp vte-0.44.2.orig/src/vtegtk.cc vte-0.44.2/src/vtegtk.cc
--- vte-0.44.2.orig/src/vtegtk.cc 2024-06-12 14:05:57.090281502 -0500
+++ vte-0.44.2/src/vtegtk.cc 2024-06-12 14:10:02.915961119 -0500
@@ -63,6 +63,42 @@
#define VTE_TERMINAL_CSS_NAME "vte-terminal"
+#define min(a,b) ((a) < (b) ? (a) : (b))
+#define max(a,b) ((a) > (b) ? (a) : (b))
+#define clamp(a,b,c) min(max(a,b),c)
+
+static inline void
+sanitise_widget_size_request(int* minimum,
+ int* natural) noexcept
+{
+ // Overly large size requests will make gtk happily allocate
+ // a window size over the window system's limits (see
+ // e.g. https://gitlab.gnome.org/GNOME/vte/-/issues/2786),
+ // leading to aborting the whole process.
+ // The toolkit should be in a better position to know about
+ // these limits and not exceed them (which here is certainly
+ // possible since our minimum sizes are very small), let's
+ // limit the widget's size request to some large value
+ // that hopefully is within the absolute limits of
+ // the window system (assumed here to be int16 range,
+ // and leaving some space for the widgets that contain
+ // the terminal).
+ auto const limit = (1 << 15) - (1 << 12);
+
+ if (*minimum > limit || *natural > limit) {
+ static auto warned = false;
+
+ if (!warned) {
+ g_warning("Widget size request (minimum %d, natural %d) exceeds limits\n",
+ *minimum, *natural);
+ warned = true;
+ }
+ }
+
+ *minimum = min(*minimum, limit);
+ *natural = clamp(*natural, *minimum, limit);
+}
+
struct _VteTerminalClassPrivate {
GtkStyleProvider *style_provider;
};
@@ -288,6 +324,7 @@ vte_terminal_get_preferred_width(GtkWidg
{
VteTerminal *terminal = VTE_TERMINAL(widget);
IMPL(terminal)->widget_get_preferred_width(minimum_width, natural_width);
+ sanitise_widget_size_request(minimum_width, natural_width);
}
static void
@@ -297,6 +334,7 @@ vte_terminal_get_preferred_height(GtkWid
{
VteTerminal *terminal = VTE_TERMINAL(widget);
IMPL(terminal)->widget_get_preferred_height(minimum_height, natural_height);
+ sanitise_widget_size_request(minimum_height, natural_height);
}
static void