Window constructor crashes on compositors without fractional-scale, xdg-decoration or viewporter (null globals) #162

Closed
opened 2026-10-06 13:25:46 +00:00 by jorijnvdgraaf · 1 comment

Summary

The Window constructor uses three optional Wayland globals without checking that the compositor advertised them. On a compositor that lacks any one of them the constructor passes a null proxy to libwayland and crashes. Line numbers refer to 6aa0338.

Details

Device::handle_global binds these when they are advertised (implementations/Crafter.Graphics-Device.cpp:277-282), and Device::Initialize only verifies wl_shm, wl_compositor and xdg_wm_base (:527):

Global Used unconditionally at
wp_fractional_scale_manager_v1 implementations/Crafter.Graphics-Window.cpp:295
zxdg_decoration_manager_v1 :302
wp_viewporter :305

The rest of the code half-anticipates this: Resize already guards if (wpViewport) (:544).

Found by reading the code. Not reproduced: the compositors at hand (phoc on the Fairphone 6, and the desktop session) advertise all three. The likely first victim is a compositor without xdg-decoration; to my knowledge GNOME's Mutter does not implement it.

Suggested fix

Guard each use and degrade:

  • no fractional-scale manager → integer scale from wl_output / wl_surface.preferred_buffer_scale, or 1.0;
  • no decoration manager → skip the decoration request (the window is then undecorated or client-decorated);
  • no viewporter → skip the viewport, which also means no fractional scaling.
## Summary The `Window` constructor uses three optional Wayland globals without checking that the compositor advertised them. On a compositor that lacks any one of them the constructor passes a null proxy to libwayland and crashes. Line numbers refer to `6aa0338`. ## Details `Device::handle_global` binds these when they are advertised (`implementations/Crafter.Graphics-Device.cpp:277-282`), and `Device::Initialize` only verifies `wl_shm`, `wl_compositor` and `xdg_wm_base` (`:527`): | Global | Used unconditionally at | |---|---| | `wp_fractional_scale_manager_v1` | `implementations/Crafter.Graphics-Window.cpp:295` | | `zxdg_decoration_manager_v1` | `:302` | | `wp_viewporter` | `:305` | The rest of the code half-anticipates this: `Resize` already guards `if (wpViewport)` (`:544`). Found by reading the code. Not reproduced: the compositors at hand (phoc on the Fairphone 6, and the desktop session) advertise all three. The likely first victim is a compositor without xdg-decoration; to my knowledge GNOME's Mutter does not implement it. ## Suggested fix Guard each use and degrade: - no fractional-scale manager → integer scale from `wl_output` / `wl_surface.preferred_buffer_scale`, or 1.0; - no decoration manager → skip the decoration request (the window is then undecorated or client-decorated); - no viewporter → skip the viewport, which also means no fractional scaling.
Author
Owner

Fixed in 670df31. The constructor makes the fractional scale, the decoration and the viewport only when the compositor advertised their globals, and the fractional scale only alongside a viewport, since the preferred scale is applied through it: without one, scale stays 1 and the compositor scales the window up on a HiDPI output. Without xdg-decoration the window has no title bar. tests/WindowOptionalGlobals hides each global, and all three, and renders, resizes and closes a window each time; it crashed on the window without xdg-decoration before the fix. Checked as well through a socket proxy that drops the three globals from KWin's registry, so the library never sees them.

Not done: the integer-scale fallback (wl_surface.preferred_buffer_scale, wl_output.scale). It needs wl_compositor v6 (the library binds v3) and a wl_surface listener, or output tracking for compositors too old for v6, and would run into #165 (a scale that changes after construction is only applied by the next resize).

Fixed in 670df31. The constructor makes the fractional scale, the decoration and the viewport only when the compositor advertised their globals, and the fractional scale only alongside a viewport, since the preferred scale is applied through it: without one, `scale` stays 1 and the compositor scales the window up on a HiDPI output. Without xdg-decoration the window has no title bar. `tests/WindowOptionalGlobals` hides each global, and all three, and renders, resizes and closes a window each time; it crashed on the window without xdg-decoration before the fix. Checked as well through a socket proxy that drops the three globals from KWin's registry, so the library never sees them. Not done: the integer-scale fallback (`wl_surface.preferred_buffer_scale`, `wl_output.scale`). It needs `wl_compositor` v6 (the library binds v3) and a `wl_surface` listener, or output tracking for compositors too old for v6, and would run into #165 (a scale that changes after construction is only applied by the next resize).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Catcrafts/Crafter.Graphics#162
No description provided.