EXC_BAD_ACCESS in AXSerializeCFType

I have an Electron app on macOS Sonoma (arm64 arch). It has a native addon (app.node) using node-addon-api. Recently it crashed, with the stack trace (given below). What is the AXSerializeCFType function inside the AXUIElementCopyAttributeValue function, and why did it crash there?

AXUIElementRef systemWideElement = AXUIElementCreateSystemWide();
AXUIElementRef focusedApp = NULL;
AXError error = AXUIElementCopyAttributeValue(systemWideElement, kAXFocusedApplicationAttribute, (CFTypeRef *)&focusedApp);

The crash appears to be occurring in the last line of the code, where I am retrieving the focused app AXUIElementRef using AXUIElementCopyAttributeValue. I have already attempted to manually set systemWideElement to NULL, but AXUIElementCopyAttributeValue is not crashing; it is just returning an error kAXErrorIllegalArgument.

OS Version: macOS 14.5 (23F79)
Report Version: 104
Crashed Thread: 344454
Application Specific Information:
Fatal Error: EXC_BAD_ACCESS / KERN_INVALID_ADDRESS / 0x102674000
Thread 344454 Crashed:
0 HIServices 0x18cb5d970 AXSerializeCFType
1 HIServices 0x18cb7ca24 serializeWrapper
2 HIServices 0x18cb7cd40 _AXXMIGCopyAttributeValue
3 HIServices 0x18cb74884 _AXUIElementCopyAttributeValue
4 HIServices 0x18cb74a04 AXUIElementCopyAttributeValue
5 HIServices 0x18cb747fc _AXUIElementCopyAttributeValue
6 HIServices 0x18cb74a04 AXUIElementCopyAttributeValue
7 app.node 0x1027a56f4 getFocusedApplication

Please post a full crash report, using the instructions in Posting a Crash Report.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Please reply as a reply. I’m not notified if you reply in the comments. See Quinn’s Top Ten DevForums Tips for this and more tips.

we only got this stack trace from the Sentry logging for the thread in which the crash happened.

OK. I don’t work with third-party crash reports because they can’t be trusted. See Implementing Your Own Crash Reporter for the details.

I recommend that you disable your third-party crash reporter and see if you can get an Apple crash report for this. If you’re not prepared to disable your third-party crash report, you should at least ensure that it preserves the Apple crash report. The above-mentioned post discusses that idea in some detail.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

EXC_BAD_ACCESS in AXSerializeCFType
 
 
Q