File vte-widget-size-limits.patch of Package vte.34433
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.58.3.orig/src/vtegtk.cc vte-0.58.3/src/vtegtk.cc
--- vte-0.58.3.orig/src/vtegtk.cc 2019-11-22 15:36:35.000000000 -0600
+++ vte-0.58.3/src/vtegtk.cc 2024-06-12 02:36:30.187929823 -0500
@@ -66,6 +66,38 @@
#define VTE_TERMINAL_CSS_NAME "vte-terminal"
+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 = std::min(*minimum, limit);
+ *natural = std::clamp(*natural, *minimum, limit);
+}
+
struct _VteTerminalClassPrivate {
GtkStyleProvider *style_provider;
};
@@ -289,6 +321,7 @@ vte_terminal_get_preferred_width(GtkWidg
{
VteTerminal *terminal = VTE_TERMINAL(widget);
WIDGET(terminal)->get_preferred_width(minimum_width, natural_width);
+ sanitise_widget_size_request(minimum_width, natural_width);
}
static void
@@ -298,6 +331,7 @@ vte_terminal_get_preferred_height(GtkWid
{
VteTerminal *terminal = VTE_TERMINAL(widget);
WIDGET(terminal)->get_preferred_height(minimum_height, natural_height);
+ sanitise_widget_size_request(minimum_height, natural_height);
}
static void