From 87ae269b8279572c0c33aaf84437fbee936821b8 Mon Sep 17 00:00:00 2001 From: brandon s allbery kf8nh Date: Wed, 19 Apr 2023 11:14:24 -0400 Subject: [PATCH] Put a cap on window names It turns out qutebrowser will place an entire `data:` URL in `_NET_WM_NAME`, up to at least 389K characters including newlines and possibly binary characters. Clamping window titles to the first line, and to 2K chars because `defaultShrinker` is quadratic in the title length. --- XMonad/Layout/Decoration.hs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/XMonad/Layout/Decoration.hs b/XMonad/Layout/Decoration.hs index f9225510..c83d1b1e 100644 --- a/XMonad/Layout/Decoration.hs +++ b/XMonad/Layout/Decoration.hs @@ -400,7 +400,11 @@ updateDecos s t f = mapM_ $ updateDeco s t f -- structure and the needed 'Rectangle's updateDeco :: Shrinker s => s -> Theme -> XMonadFont -> (OrigWin,DecoWin) -> X () updateDeco sh t fs ((w,_),(Just dw,Just (Rectangle _ _ wh ht))) = do - nw <- getName w + -- xmonad-contrib #809 + -- qutebrowser will happily shovel a 389K multiline string into @_NET_WM_NAME@ + -- and the 'defaultShrinker' (a) doesn't handle multiline strings well (b) is + -- quadratic due to using 'init' + nw <- fmap (take 2048 . takeWhile (/= '\n') . show) (getName w) ur <- readUrgents dpy <- asks display let focusColor win ic ac uc = maybe ic (\focusw -> case () of @@ -414,7 +418,7 @@ updateDeco sh t fs ((w,_),(Just dw,Just (Rectangle _ _ wh ht))) = do (urgentColor t, urgentBorderColor t, urgentBorderWidth t, urgentTextColor t) let s = shrinkIt sh name <- shrinkWhile s (\n -> do size <- io $ textWidthXMF dpy fs n - return $ size > fromIntegral wh - fromIntegral (ht `div` 2)) (show nw) + return $ size > fromIntegral wh - fromIntegral (ht `div` 2)) nw let als = AlignCenter : map snd (windowTitleAddons t) strs = name : map fst (windowTitleAddons t) i_als = map snd (windowTitleIcons t)