From 34142c1b6276eedfcf01c8a49e5f80c9a578be41 Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Tue, 26 Apr 2022 11:29:09 -0700 Subject: [PATCH] Fix gtk_widget_measure infinite loop issue (#2071228) --- ...72fb8e55fa2176d019dd5875a667ed8d3fbc.patch | 85 +++++++++++++++++++ gtk4.spec | 11 ++- 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 90e372fb8e55fa2176d019dd5875a667ed8d3fbc.patch diff --git a/90e372fb8e55fa2176d019dd5875a667ed8d3fbc.patch b/90e372fb8e55fa2176d019dd5875a667ed8d3fbc.patch new file mode 100644 index 0000000..e95d87c --- /dev/null +++ b/90e372fb8e55fa2176d019dd5875a667ed8d3fbc.patch @@ -0,0 +1,85 @@ +From 90e372fb8e55fa2176d019dd5875a667ed8d3fbc Mon Sep 17 00:00:00 2001 +From: Benjamin Otte +Date: Tue, 26 Apr 2022 19:51:16 +0200 +Subject: [PATCH] boxlayout: Do not infloop + +if the loop for determining max width grows too big, print an error and +abort assuming that a satisfactory value was reached. + +This will cause wrong layout and might cause widgets to overlap, but it +will not infloop. +--- + gtk/gtkboxlayout.c | 43 +++++++++++++++++++++++++++++++++++++++++-- + 1 file changed, 41 insertions(+), 2 deletions(-) + +diff --git a/gtk/gtkboxlayout.c b/gtk/gtkboxlayout.c +index e79c5e202a..5d1b63169d 100644 +--- a/gtk/gtkboxlayout.c ++++ b/gtk/gtkboxlayout.c +@@ -288,6 +288,12 @@ gtk_box_layout_compute_opposite_size (GtkBoxLayout *self, + *natural = largest_nat; + } + ++/* if widgets haven't reached their min opposite size at this ++ * huge value, things went massively wrong and we need to bail to not ++ * cause an infinite loop. ++ */ ++#define MAX_ALLOWED_SIZE (1 << 20) ++ + static int + distribute_remaining_size (GtkRequestedSize *sizes, + gsize n_sizes, +@@ -321,7 +327,40 @@ distribute_remaining_size (GtkRequestedSize *sizes, + { + int test; + +- if (max == G_MAXINT) ++ if (min > MAX_ALLOWED_SIZE) ++ { ++ /* sanity check! */ ++ for (i = 0; i < n_sizes; i++) ++ { ++ int check_min, check_nat; ++ gtk_widget_measure (sizes[i].data, ++ orientation, ++ MAX_ALLOWED_SIZE, ++ &sizes[i].minimum_size, &sizes[i].natural_size, ++ NULL, NULL); ++ gtk_widget_measure (sizes[i].data, ++ orientation, ++ -1, ++ &check_min, &check_nat, ++ NULL, NULL); ++ if (check_min < sizes[i].minimum_size) ++ { ++ g_critical ("%s %p reports a minimum %s of %u, but minimum %s for %s of %u is %u. Expect overlapping widgets.", ++ G_OBJECT_TYPE_NAME (sizes[i].data), sizes[i].data, ++ orientation == GTK_ORIENTATION_HORIZONTAL ? "width" : "height", ++ check_min, ++ orientation == GTK_ORIENTATION_HORIZONTAL ? "width" : "height", ++ orientation == GTK_ORIENTATION_HORIZONTAL ? "height" : "width", ++ MAX_ALLOWED_SIZE, sizes[i].minimum_size); ++ sizes[i].minimum_size = check_min; ++ sizes[i].natural_size = check_nat; ++ } ++ total_size += sizes[i].minimum_size; ++ } ++ return MAX (0, available - total_size); ++ } ++ ++ if (max == MAX_ALLOWED_SIZE) + test = min * 2; + else + test = (min + max) / 2; +@@ -465,7 +504,7 @@ gtk_box_layout_compute_opposite_size_for_size (GtkBoxLayout *self, + self->orientation, + available, + min_size, +- G_MAXINT); ++ MAX_ALLOWED_SIZE); + + /* Bring children up to size first */ + available = gtk_distribute_natural_allocation (available, nvis_children, sizes); +-- +GitLab + diff --git a/gtk4.spec b/gtk4.spec index 537383b..01e425f 100644 --- a/gtk4.spec +++ b/gtk4.spec @@ -17,7 +17,7 @@ Name: gtk4 Version: 4.6.2 -Release: 2%{?dist} +Release: 3%{?dist} Summary: GTK graphical user interface library License: LGPLv2+ @@ -28,6 +28,12 @@ Source0: https://download.gnome.org/sources/gtk/4.6/gtk-%{version}.tar.xz # https://gitlab.gnome.org/GNOME/gtk/-/issues/4805 # https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/4605 Patch0: 0001-gtkimmulticontext-Handle-switches-between-displays.patch +# Fix "gtk_widget_measure: assertion 'for_size >= -1' failed" loop bug +# Patch proposed by Benjamin Otte, no MR yet +# https://bugzilla.redhat.com/show_bug.cgi?id=2071228 +# https://gitlab.gnome.org/GNOME/gtk/-/issues/4517 +# https://gitlab.gnome.org/GNOME/gtk/-/commit/90e372fb8e55fa2176d019dd5875a667ed8d3fbc +Patch1: 90e372fb8e55fa2176d019dd5875a667ed8d3fbc.patch BuildRequires: cups-devel BuildRequires: desktop-file-utils @@ -232,6 +238,9 @@ desktop-file-validate %{buildroot}%{_datadir}/applications/*.desktop %{_mandir}/man1/gtk4-widget-factory.1* %changelog +* Tue Apr 26 2022 Adam Williamson - 4.6.2-2.1awb +- Fix from Benjamin for gtk_widget_measure infinite loop issue (#2071228) + * Thu Mar 31 2022 Adam Williamson - 4.6.2-2 - Backport MR #4605 to fix portal save/load dialogs on X (#2068041)