Skip to content

Commit 97dd328

Browse files
committed
linux: fix heap corruption in _wait_for_map XWindowAttributes buffer
The _XWA ctypes Structure declared only 18 of the 23 fields of XWindowAttributes, giving ctypes.sizeof(_XWA) == 96. XGetWindowAttributes writes the full 136-byte struct regardless, so all_event_masks (offset 96) landed in the 8-byte tail guard of the adjacent Python debug allocation, corrupting the heap. Add the five missing fields (all_event_masks, your_event_mask, do_not_propagate_mask, override_redirect, screen) so the buffer is the correct 136 bytes on LP64.
1 parent 9597b25 commit 97dd328

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/handlers/browser_process_handler.pyx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ IF UNAME_SYSNAME == "Linux":
6262

6363
_x11.XGetWindowAttributes.restype = _ct.c_int
6464

65-
# XWindowAttributes struct — fields up to map_state (LP64 layout).
66-
# ctypes.Structure handles natural alignment automatically.
65+
# Full XWindowAttributes struct (LP64 layout, 136 bytes).
66+
# All fields must be declared; omitting trailing fields truncates the
67+
# buffer to 96 bytes and XGetWindowAttributes writes all_event_masks
68+
# (offset 96) past the end, corrupting adjacent heap memory.
6769
class _XWA(_ct.Structure):
6870
_fields_ = [
6971
("x", _ct.c_int), ("y", _ct.c_int),
@@ -75,6 +77,11 @@ IF UNAME_SYSNAME == "Linux":
7577
("backing_planes", _ct.c_ulong), ("backing_pixel", _ct.c_ulong),
7678
("save_under", _ct.c_int), ("colormap", _ct.c_ulong),
7779
("map_installed", _ct.c_int), ("map_state", _ct.c_int),
80+
("all_event_masks", _ct.c_long),
81+
("your_event_mask", _ct.c_long),
82+
("do_not_propagate_mask", _ct.c_long),
83+
("override_redirect", _ct.c_int),
84+
("screen", _ct.c_void_p),
7885
]
7986

8087
_browser_ref = [browser]

0 commit comments

Comments
 (0)