From b66e5fd422820460f030db853109e4d50bb3549d Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Fri, 18 Dec 2020 23:43:11 +0000 Subject: [PATCH] win: sanitize _NET_FRAME_EXTENTS values Shouldn't crash picom for window manager bugs. Related: https://github.com/yshui/picom/issues/270#issuecomment-748210643 Signed-off-by: Yuxuan Shui --- src/win.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/win.c b/src/win.c index c71df1a..d4db157 100644 --- a/src/win.c +++ b/src/win.c @@ -1914,12 +1914,18 @@ void win_update_frame_extents(session_t *ps, struct managed_win *w, xcb_window_t XCB_ATOM_CARDINAL, 32); if (prop.nitems == 4) { - const int32_t extents[4] = { - to_int_checked(prop.c32[0]), - to_int_checked(prop.c32[1]), - to_int_checked(prop.c32[2]), - to_int_checked(prop.c32[3]), - }; + int extents[4]; + for (int i = 0; i < 4; i++) { + if (prop.c32[i] > (uint32_t)INT_MAX) { + log_warn("Your window manager sets a absurd " + "_NET_FRAME_EXTENTS value (%u), ignoring it.", + prop.c32[i]); + memset(extents, 0, sizeof(extents)); + break; + } + extents[i] = (int)prop.c32[i]; + } + const bool changed = w->frame_extents.left != extents[0] || w->frame_extents.right != extents[1] || w->frame_extents.top != extents[2] ||