Tk Source Code

Attachment Details
Login
Overview

Artifact ID: 79654caefce66c6a9e9190e9b8ca746d9c7338cc29f21912c0d455505075035b
Ticket: b964b98d1b1fa9bc1abf08a09bcaef20c4ed0baf
Date: 2026-07-05 15:45:26
User: anonymous
Artifact Attached: ffe73d4baae9976f8c45b39b3a777017c3ff5a7d97dc301f89ccff1b22fb476e
Filename:tk-macos-ttk-uaf-9.0.3.patch
Description:Fix attached: the ttk manager relayout UAF is re-entrancy during content placement. Patch against Tk 9.0.3, patch -p1 from the source root; 3 files. Root cause (refined): Ttk_PlaceContent() -> Tk_MaintainGeometry() -> Tk_MoveResizeWindow() delivers <Configure> synchronously; on Aqua, window ops also pump the Cocoa run loop. A binding or a content window <Destroy> serviced there runs RemoveContent() mid-placement, freeing the Ttk_Content the manager still holds - the next Tk_MapWindow(content->window) on freed memory is the EXC_BAD_ACCESS. (Hits X11 too via a synchronous <Configure> binding; just pumped less reliably there.) Fix: (1) ttkManager.c - an epoch counter bumped on every content[] mutation; placement/map/idle routines bail if it changed after a call into Tk (+ TK_ALREADY_DEAD / bounds / no-re-arm guards). (2) tkGeometry.c - Tcl_Preserve both windows across Tk_MoveResizeWindow and a TK_ALREADY_DEAD guard before the direct-child map (the crash site). (3) ttkPanedwindow.c - hoist the pane->sashPos read before placement can free pane. Validation: deterministic repro 100%->0 on Aqua and X11; app churn stress 0 crashes on macOS/arm64 (was ~42% / 100%); tests/ttk 200/200 before and after. No build flag; size_t epoch; gcc + clang clean. ---- Full disclosure: The patch and the description above were both AI generated after a debug session.
Content:
(file is 8413 bytes of binary data)