cua icon indicating copy to clipboard operation
cua copied to clipboard

cua-driver 0.14.1 SIGSEGV on x86_64 macOS 14.1.2 (Sonoma) —

Open fengyaojieTTT opened this issue 4 months ago • 4 comments

cua-driver 0.14.1 SIGSEGV on x86_64 macOS 14.1.2 (Sonoma) — SLSEventAuthenticationMessageCreateData null ptr in activate_without_raise

Summary

cua-driver 0.14.1 serve daemon crashes with SIGSEGV when performing pixel-coordinate click (via activate_without_raise) on x86_64 macOS 14.1.2 (Sonoma). This is a different crash from #1503 — that issue was NSInvalidArgumentException (ObjC selector not found), this one is EXC_BAD_ACCESS (null pointer dereference) inside the C function SLSEventAuthenticationMessageCreateData.

Crash

Exception:  EXC_BAD_ACCESS (SIGSEGV)
  subtype:   UNKNOWN_0xD at 0x0000000000000000
  signal:    Segmentation fault: 11
  faultingThread: 14 (tokio-rt-worker)

Crash Stack (faulting thread)

0  objc_msgSend
1  _encodeObject
2  +[NSKeyedArchiver archivedDataWithRootObject:requiringSecureCoding:error:]
3  SLSEventAuthenticationMessageCreateData           ← C function, null ptr here
4  _SLEventRecordCreateData(SLEventRecord const*, SLEventCreateDataOptions, unsigned int)
5  CGSEncodeEventRecord
6  SLPSPostEventRecordTo
7  activate_without_raise                           ← cua-driver entry point
8  ClickTool::invoke                                ← click tool handler

Root Cause

The #1503 fix added class_respondsToSelector guard to skip messageWithEventRecord:pid:version: on macOS 14 where the ObjC selector doesn't exist. However, on x86_64 macOS 14.1.2, the code path reaches SLSEventAuthenticationMessageCreateData — a C function (not an ObjC method dispatch) — which internally calls NSKeyedArchiver archivedDataWithRootObject:requiringSecureCoding:error: on an object that is null/invalid, causing SIGSEGV.

The class_respondsToSelector guard from #1503 does5 does not protect against this crash because:

  • The C function SLSEventAuthenticationMessageCreateData is called directly (not via ObjC message dispatch)
  • The crash happens inside the C function during event record serialization, not at the selector dispatch point

Reproduction

  1. Install cua-driver 0.14.1 on x86_64 macOS 14.1.2
  2. Start serve daemon: cua-driver serve --autostart
  3. Attempt a pixel-coordinate click on any window: echo '{"pid":<PID>,"window_id":<WID>,"x":200,"y":57}' | cua-driver click
  4. Daemon crashes immediately with SIGSEGV

Reproduced 11 times in a single session, 100% reproducible.

Environment

  • macOS: 14.1.2 (23B92) Sonoma
  • Architecture: x86_64 (Intel Core i7-1068NG7)
  • Model: MacBookPro16,2
  • cua-driver: 0.14.1 (universal binary, running x86_64 slice)
  • Binary: /Users/fengyaojie/.local/bin/cua-driver (universal: x86_64 + arm64)
  • CuaDriver.app: /Applications/CuaDriver.app (universal: x86_64 + arm64)

Difference from #1503

#1503 (fixed) This issue
Exception NSInvalidArgumentException EXC_BAD_ACCESS / SIGSEGV
Crash point messageWithEventRecord:pid:version: (ObjC selector) SLSEventAuthenticationMessageCreateData (C function)
Architecture arm64 (M1 Pro) x86_64 (Intel)
macOS 14.8.7 14.1.2
Fix class_respondsToSelector guard ❌ Not covered by that guard

Suggested Fix

The activate_without_raise path should be guarded at the SLSEventAuthenticationMessageCreateData call site (or higher at SLPSPostEventRecordTo) on macOS 14 x86_64, falling back to CGEventPostToPid without the auth envelope — similar to the graceful degradation already implemented for the ObjC selector path.

Alternatively, check macOS version + architecture before calling the SkyLight auth-message path, since this C function appears to have a null-pointer bug on x86_64 Sonoma.

Workaround

  • capture and set_value (AX operations) work fine in background mode
  • click via AXPress works for native AppKit controls
  • Pixel-coordinate click and type via CGEvent crash the daemon
  • Foreground typeE foreground type (keystrokes) works but briefly steals focus

fengyaojieTTT avatar Jul 30 '26 09:07 fengyaojieTTT

Thanks @fengyaojieTTT. The macOS activation and click paths have changed substantially since 0.14.1, and 0.30.4 ships an x86_64 build. Could you repeat the pixel click that crashed on macOS 14 with 0.30.4 and attach the crash report if it still crashes?

f-trycua avatar Sep 29 '26 18:09 f-trycua

Still reproduces on 0.33.0, on arm64 (not only x86_64), macOS 14.6.

Environment

  • cua-driver 0.33.0 (cua-driver-rs-v0.33.0, darwin-universal release tarball; CuaDriver.app signature verified, run natively — not translated)
  • macOS 14.6 (23G80), Apple Silicon (Mac15,10)
  • Accessibility + Screen Recording granted to com.trycua.driver (check_permissions reports both true)

Repro

Daemon started with open -n -g CuaDriver.app --args serve, then via cua-driver call with one shared session label:

  1. get_window_state on the target window (include_accessibility_tree: false) → returns a capture_id
  2. click with x, y, that capture_id, default delivery_mode (background), while another app is frontmost

→ the daemon dies with SIGSEGV; the CLI gets daemon closed connection without response.

Reproduced twice with different targets — a Qt app window and a plain Finder window — so it is not target-specific.

For contrast, on the same machine:

  • click with delivery_mode: "foreground" works
  • background type_text / press_key / hotkey (the pid_keyboard route) work

Crash (faulting thread, tokio-rt-worker; identical in both reports)

Exception: EXC_BAD_ACCESS (SIGSEGV)
KERN_INVALID_ADDRESS at 0x0000c3ffa9427c08 -> 0x000043ffa9427c08 (possible pointer authentication failure)

0  libobjc.A.dylib  objc_msgSend
1  Foundation       _encodeObject
2  Foundation       +[NSKeyedArchiver archivedDataWithRootObject:requiringSecureCoding:error:]
3  SkyLight         _SLEventRecordCreateData(SLSEventRecord const*, SLEventCreateDataOptions, unsigned int)
4  SkyLight         CGSEncodeEventRecord
5  SkyLight         SLPSPostEventRecordTo
6  cua-driver       platform_macos::input::skylight::activate_without_raise
7  cua-driver       platform_macos::tools::click::ClickTool::invoke (blocking task)

Same path as the original report (SLPSPostEventRecordTo → _SLEventRecordCreateData → NSKeyedArchiver from activate_without_raise), except no separate SLSEventAuthenticationMessageCreateData frame shows on this build, and the fault is a PAC-style invalid address rather than a null pointer.

Happy to test a build or provide more detail.

JaydonZhao avatar Oct 03 '26 21:10 JaydonZhao

Another reproduction on Apple Silicon, macOS 14.8.3 (23J220), Mac mini (Macmini9,1), cua-driver 0.30.4 (signed CuaDriver.app, Accessibility and Screen Recording granted, cua-driver doctor all green).

Frequency: 4 daemon crashes on 2026-10-01 (10:32, 11:52, 12:13, 12:27 local) with EXC_BAD_ACCESS / SIGSEGV, KERN_INVALID_ADDRESS ... (possible pointer authentication failure). Further daemon deaths ("daemon closed connection without response", then "daemon is not running") on 2026-10-05 and 2026-10-06.

Trigger: each crash followed a background pixel click, i.e. click with pid, window_id, x, y and the default delivery_mode: "background", no element_token. Example call five seconds before the 2026-10-05 death: cua-driver call click '{"pid":…,"window_id":…,"capture_id":"…","x":1459,"y":814}' We have not seen a crash on element_token (AX) clicks.

Crashed-thread stack (identical in all four reports, top first):

objc_msgSend
_encodeObject
+[NSKeyedArchiver archivedDataWithRootObject:requiringSecureCoding:error:]
_SLEventRecordCreateData(SLSEventRecord const*, SLEventCreateDataOptions, unsigned int)
CGSEncodeEventRecord
SLPSPostEventRecordTo
platform_macos::input::skylight::activate_without_raise
platform_macos::tools::click::ClickTool::invoke (tokio blocking task)

Versions checked: skylight.rs, mouse.rs and pixel_route.rs are byte-identical between 0.30.4 and 0.31.0. On current main, activate_without_raise still posts the raw 248-byte focus/defocus record through SLPSPostEventRecordTo (around skylight.rs:510–550). This agrees with the 0.33.0 arm64 / macOS 14.6 report above.

Hypothesis (not proven): on macOS 14, SLPSPostEventRecordTo serializes its second argument as an SLSEventRecord object (CGSEncodeEventRecord → NSKeyedArchiver). A raw byte buffer then gets messaged as an object, which matches the objc_msgSend fault. If that is right, a macOS-version gate on the no-raise path (or falling back to the foreground rung on 14.x) would avoid the crash.

Workaround we use: element_token clicks first. When only pixels work, delivery_mode: "foreground" with window_id.

DmytroVolodymyrson avatar Oct 07 '26 21:10 DmytroVolodymyrson

0.38.0 on arm64 / macOS 14.4.1: same SkyLight serialization crash reached from a background AXPress in Calculator

An additional observed case on cua-driver 0.38.0 may help narrow this issue. Unlike the earlier pixel-click reports, this failure was reached through the accessibility click route in Apple's Calculator.

Environment:

  • macOS 14.4.1, build 23E224
  • MacBookPro17,1 (Apple Silicon)
  • cua-driver 0.38.0, native ARM-64 execution (translated: false)
  • Hermes wrapper using structured snapshots/element tokens; its adapter compatibility fixes do not modify the CUA executable

Observed operation:

  1. Capture a separate Calculator window in the background and resolve the AXButton labelled 7 from that fresh snapshot.
  2. Request one background click by element handle/token, not by pixel coordinates.
  3. The caller receives Connection closed. The corresponding crash report, captured on 2026-10-26, records SIGSEGV on tokio-rt-worker thread 17.

Reduced crashed-thread stack:

objc_msgSend
_encodeObject
+[NSKeyedArchiver archivedDataWithRootObject:requiringSecureCoding:error:]
_SLEventRecordCreateData
CGSEncodeEventRecord
SLPSPostEventRecordTo
platform_macos::input::skylight::activate_without_raise_with
platform_macos::tools::click::perform_ax_click

The exception is EXC_BAD_ACCESS / KERN_INVALID_ADDRESS, with the report saying possible pointer authentication failure. Register symbolization associates x0 with __41-[NSRunningApplication processIdentifier]_block_invoke; that is an observation, not a demonstrated object-lifetime or ABI diagnosis.

This path is consistent with the pinned 0.38.0 source: perform_ax_click calls prime_key_window_for_background_press for non-foreground actions; a background native AXPress can enter activate_without_raise_with before AXUIElementPerformAction. Using an element token therefore does not necessarily avoid the affected SkyLight path in this version.[3]

Limited comparison already performed, not a new test for this report: running the same vendor app under its x86_64 slice via existing Rosetta support allowed two background AX presses in the Calculator scenario. Independent captures showed 0 -> 7 -> 0. The driver itself reported effect unverifiable; the visible state change was established by subsequent captures. This is not an endurance test, a Mail workflow result, or evidence that x86_64 is generally safe—this issue already includes an Intel reproduction.

No overlay-off A/B comparison or foreground comparison has been performed for this local case. Concurrent rendering on the main thread is not being claimed as the root cause. No new live reproduction was run during preparation of this comment.

Expected behavior: either a successful background AX action or an explicit structured refusal when this private activation recipe is unsafe; not process termination and not an unannounced switch to foreground input.

Could maintainers confirm whether this should remain under #2688, and investigate the private event-record/serialization boundary and the AX key-window-priming caller on Sonoma? A guarded diagnostic build would be preferable to repeated uncontrolled clicks. Any further testing here will require a separately scoped harmless test.

Sources

[3] https://raw.githubusercontent.com/trycua/cua/cua-driver-rs-v0.38.0/libs/cua-driver/rust/crates/platform-macos/src/tools/click.rs

AndyGraunke avatar Oct 27 '26 11:10 AndyGraunke