Wayland touch: a finger's slot keeps a destroyed window unless it was the touch window, so its next motion or up uses freed memory #191
Labels
No labels
claude:blocked
claude:done
claude:failed
claude:in-progress
claude:ready
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Catcrafts/Crafter.Graphics#191
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Every finger that is down has a
TouchSlotholding the window it went down on, andtouch_upandtouch_motiontake the window from the slot, since those events carry no surface.~Windowforgets the slots only when the window being destroyed isDevice::touchWindow, the window of the last finger down. With fingers on two windows, destroying the other one leaves its fingers' slots pointing at it, and the nextwl_touch.motionorwl_touch.upfor such a finger writes to the freed window and fires its events. Line numbers refer toc006519.Details
implementations/Crafter.Graphics-Device.cpp:725and:732:touch_downsetstouchWindow = windowandslot->window = window.implementations/Crafter.Graphics-Window.cpp:695-698:~WindowrunsDevice::ForgetTouches()onlyif (Device::touchWindow == this).Device.cpp:754(touch_up) and:774(touch_motion):window = slot->window, thenwindow->lastInputTime = time,window->onTouchUp.Invoke(...)oronTouchMove.Invoke(...), and the reads ofwindow->primaryTouchIdafter them.Concrete case
Finger 7 goes down on window A: slot 7 holds A, and
touchWindowis A. Finger 8 goes down on window B:touchWindowis B. A is destroyed.touchWindowis B, so slot 7 keeps A. Finger 7 moves or lifts:touchWindowis not null,SlotFor(7)finds the slot, and the handler uses A.A slot whose up never comes also stays
used, soAnyTouch()stays true andtouch_upno longer clearstouchWindow(:767) until a later finger goes down with the same id.Found by reading the code, in the pre-push review of 364d210..c006519. It is older than that range, which added one write through the same pointer. Not reproduced, and whether a compositor still sends motion or up for a touch point whose surface is gone was not checked against one.
Suggested fix
In
~Window, clear every slot whosewindowisthis, whichever windowtouchWindowis, and cleartouchWindowwhen it isthisor no slot is left in use.