[gnome-terminal/wip/rishi/window-title-truncate] window: Limit the title's length to avoid integer overflows in Pango
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-terminal/wip/rishi/window-title-truncate] window: Limit the title's length to avoid integer overflows in Pango
- Date: Wed, 4 Mar 2020 16:57:23 +0000 (UTC)
commit ebc9a39aa003a15b2d526f45908e2b8e6df950c9
Author: Debarshi Ray <debarshir gnome org>
Date: Wed Mar 4 17:06:21 2020 +0100
window: Limit the title's length to avoid integer overflows in Pango
GtkLabels with really long texts of the order of 2^21 characters can
cause integer overflows in Pango when measuring the width of the
PangoLayout for that text. Tracking down the root cause of the overflow
in the font stack and fixing it is difficult, so it's prudent to work
around it by limiting the length of the window title to a sane, yet
large enough, number.
Pango does integer measurements in Pango units where 1 pixel is 2^10
Pango units, and font glyphs are roughly 16, or 2^4, pixels wide.
Therefore, roughly 2^(31-10-4), or 131072, characters is the threshold
after which Pango might start to overflow.
A limit of 1024 characters was chosen because that's the limit both
VTE and xterm use for titles set through the OSC 0 escape sequence.
https://gitlab.gnome.org/GNOME/gnome-terminal/issues/207
src/terminal-window.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
---
diff --git a/src/terminal-window.c b/src/terminal-window.c
index 7a8953c5..19f31fdd 100644
--- a/src/terminal-window.c
+++ b/src/terminal-window.c
@@ -2407,13 +2407,17 @@ sync_screen_title (TerminalScreen *screen,
{
TerminalWindowPrivate *priv = window->priv;
const char *title;
+ gs_free char *title_truncated = NULL;
if (screen != priv->active_screen)
return;
title = terminal_screen_get_title (screen);
- gtk_window_set_title (GTK_WINDOW (window),
- title && title[0] ? title : _("Terminal"));
+ if (title == NULL || title[0] == '\0')
+ title = _("Terminal");
+
+ title_truncated = g_utf8_substring (title, 0, 1024);
+ gtk_window_set_title (GTK_WINDOW (window), title_truncated);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]